From 14e3025a24842b66d4df2c67fec1faace5e6a4a1 Mon Sep 17 00:00:00 2001 From: dshvaika Date: Thu, 17 Sep 2026 13:15:27 +0300 Subject: [PATCH] fix(iot-hub): make the popup's Enter guard and row padding hold on their own Three things from the re-review, two of them introduced by the commit that turned the popup's header and footer into options. **The Enter guard never fired.** It asked the autocomplete trigger for its active option during keyup, but the trigger clears that inside the same keydown - it calls _selectViaInteraction and then _resetActiveItem, which with no autoActiveFirstOption sets the active index to -1. So the guard always fell through, and one Enter on a highlighted row opened it and then navigated away from it. That is worse than the behaviour before, where the click handler simply never ran. The row that acts now records it through rowSelectedByUser, which does not depend on the order the two handlers run in, and typing clears the flag since a pointer selection leaves no keyup behind it. **The header's own padding was overridden.** Under one ancestor chain, `.mat-mdc-option.tb-search-popup-group-header` and `.mat-mdc-option:not(.mat-mdc-option-multiple)` both weigh (0,4,0), and the second was declared later, so every section header shipped 8px taller than the 4px the comment above it documents - with up to six of them in a 424px panel. The catch-all could not match the old span header; it matches an option. Each row kind now carries its own class and the shared parts sit in one rule, so nothing here rests on source order. The footer had the same collision and only won by being declared last. **The hover-scrollbar block is a mixin.** This branch added a second byte-identical copy of it. Both now call tb-iot-hub-hover-scrollbar from the partial they already import. The mixin records what is deliberately NOT settled here: whether these panels should keep a thumb that is invisible until hover, and whether to add the standardised scrollbar-width / scrollbar-color that Firefox reads, is a question for the IoT Hub filter UI as a whole - iot-hub-browse and dashboard-widget-select carry the same treatment and predate this branch. --- .../components/iot-hub/_iot-hub-common.scss | 36 +++++++++++++++++ .../iot-hub/iot-hub-facet-list.component.scss | 27 +------------ .../iot-hub/iot-hub-search.component.scss | 27 +------------ .../pages/iot-hub/iot-hub-home.component.html | 8 ++-- .../pages/iot-hub/iot-hub-home.component.scss | 40 +++++++++++-------- .../pages/iot-hub/iot-hub-home.component.ts | 31 +++++++++++--- 6 files changed, 91 insertions(+), 78 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss b/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss index d247f20112..96697ebe74 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss @@ -119,3 +119,39 @@ pointer-events: none; } } + +// Scroll area that shows its thumb only while the container is hovered — the filter panels' +// own treatment, kept here so the two that use it cannot drift apart. +// +// Not the app-wide one: theme.scss keeps its thumb permanently visible. Whether these panels +// should do the same, and whether to add the standardised scrollbar-width / scrollbar-color +// that Firefox reads, is a question for the IoT Hub filter UI as a whole rather than for one +// panel; iot-hub-browse and dashboard-widget-select carry copies of this same treatment. +@mixin tb-iot-hub-hover-scrollbar { + &::-webkit-scrollbar { + width: 6px; + } + + &::-webkit-scrollbar-track { + background-color: transparent; + } + + &::-webkit-scrollbar-thumb { + background-color: transparent; + border-radius: 3px; + } + + &:hover { + &::-webkit-scrollbar-track { + background-color: rgba(0, 0, 0, 0.04); + } + + &::-webkit-scrollbar-thumb { + background-color: rgba(0, 0, 0, 0.2); + + &:hover { + background-color: rgba(0, 0, 0, 0.35); + } + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss index e5fc43f803..4df80a68e1 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss @@ -45,32 +45,7 @@ overflow-y: auto; } - &::-webkit-scrollbar { - width: 6px; - } - - &::-webkit-scrollbar-track { - background-color: transparent; - } - - &::-webkit-scrollbar-thumb { - background-color: transparent; - border-radius: 3px; - } - - &:hover { - &::-webkit-scrollbar-track { - background-color: rgba(0, 0, 0, 0.04); - } - - &::-webkit-scrollbar-thumb { - background-color: rgba(0, 0, 0, 0.2); - - &:hover { - background-color: rgba(0, 0, 0, 0.35); - } - } - } + @include tb-iot-hub-hover-scrollbar; } .tb-iot-hub-facet-search { diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss index 32c7a51458..3f946404ad 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss @@ -221,32 +221,7 @@ overflow-y: auto; padding-top: 20px; - &::-webkit-scrollbar { - width: 6px; - } - - &::-webkit-scrollbar-track { - background-color: transparent; - } - - &::-webkit-scrollbar-thumb { - background-color: transparent; - border-radius: 3px; - } - - &:hover { - &::-webkit-scrollbar-track { - background-color: rgba(0, 0, 0, 0.04); - } - - &::-webkit-scrollbar-thumb { - background-color: rgba(0, 0, 0, 0.2); - - &:hover { - background-color: rgba(0, 0, 0, 0.35); - } - } - } + @include tb-iot-hub-hover-scrollbar; } // The close button and heading belong to the narrow layout only. diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html index b2be21ac32..564f89ca46 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html @@ -86,7 +86,7 @@ } @else { @for (group of searchResultGroups; track group.type) { + (onSelectionChange)="rowSelectedByUser($event) && navigateToSection(group.type)"> {{ getSearchGroupLabel(group.type) }} @if (group.remaining > 0) { @@ -96,8 +96,8 @@ } @for (item of group.items; track item.id) { - + @if (isCompactType(item.type)) {
{{ getCompactIcon(item) }} @@ -123,7 +123,7 @@ } } + (onSelectionChange)="rowSelectedByUser($event) && seeAllResults()"> @if (searchText?.trim(); as query) { {{ 'iot-hub.see-results-for' | translate:{ search: query } }} } @else { diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss index 98b4ab0389..8a89ebae44 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss @@ -220,6 +220,27 @@ 0 114px 46px 0 rgba(0, 0, 0, 0.01), 0 178px 50px 0 rgba(0, 0, 0, 0); + // Every row of the panel shares the flex line and the highlight; the boxes differ per kind + // below. Each kind is selected by its own class rather than by leaning on source order, since + // .mat-mdc-option. and .mat-mdc-option:not(...) tie on specificity. + .mat-mdc-option { + .mdc-list-item__primary-text { + display: flex; + align-items: center; + gap: 16px; + width: 100%; + } + + &:hover:not(.mdc-list-item--disabled), + &.mat-mdc-option-active:not(.mdc-list-item--disabled) { + background: rgba(0, 0, 0, 0.04); + } + + .mat-icon, tb-icon { + margin-right: 0; + } + } + // Section header — an option like every other row, not a button beside them, so the arrow keys // reach it and a screen reader reads it in the list. It IS the way into the type page: title // left, how much is not shown plus a chevron right. There is deliberately no per-section @@ -268,26 +289,10 @@ } // Item row — Design: 8px V / 16px H, 16px gap, centered - .mat-mdc-option:not(.mat-mdc-option-multiple) { + .mat-mdc-option.tb-search-popup-item { padding: 8px 16px; min-height: auto; height: auto; - - &:hover:not(.mdc-list-item--disabled), - &.mat-mdc-option-active:not(.mdc-list-item--disabled) { - background: rgba(0, 0, 0, 0.04); - } - - .mat-icon, tb-icon { - margin-right: 0; - } - - .mdc-list-item__primary-text { - display: flex; - align-items: center; - gap: 16px; - width: 100%; - } } // Thumbnail — Design: 99px x 56px, 4px radius, 1px border, 4% bg @@ -392,6 +397,7 @@ .tb-search-popup-no-results { pointer-events: none; opacity: 1 !important; + padding: 8px 16px; } .tb-search-popup-no-results-content { diff --git a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts index 8e6038ef96..4efb672e33 100644 --- a/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts +++ b/ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts @@ -3,6 +3,7 @@ import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/core'; import { Router } from '@angular/router'; import { MatAutocompleteTrigger } from '@angular/material/autocomplete'; +import { MatOptionSelectionChange } from '@angular/material/core'; import { BreakpointObserver } from '@angular/cdk/layout'; import { forkJoin, of, Subject, Subscription } from 'rxjs'; import { catchError, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators'; @@ -66,6 +67,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { searchLoading = false; @ViewChild(MatAutocompleteTrigger) searchAutoTrigger: MatAutocompleteTrigger; @ViewChild('searchInput', {read: ElementRef}) searchInputRef: ElementRef; + private enterHandledByRow = false; private searchSubject = new Subject(); private searchSubscription: Subscription; @@ -217,6 +219,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } onSearchInput(): void { + this.enterHandledByRow = false; this.searchLoading = true; this.searchSubject.next(this.searchText || ''); } @@ -240,13 +243,31 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy { } /** - * Enter in the field opens the search page - unless the panel has an option highlighted, which - * the trigger has already acted on during keydown. This runs on keyup, which preventDefault on - * the keydown does not stop, so without the guard one Enter would both open a result and - * navigate away from it. + * Gate on every row's selection: false for the panel's own bookkeeping, true when the user + * picked the row - and then it records that this keystroke has been dealt with. + * + * One Enter reaches two handlers. The autocomplete trigger acts on keydown, the field's own + * handler on keyup, and preventDefault on the first does not stop the second. The trigger's + * activeOption cannot tell them apart either: it clears it inside that same keydown, so by + * keyup it reads empty whether or not a row acted. The row that acted says so instead, which + * does not depend on the order the two handlers run in. + */ + rowSelectedByUser(event: MatOptionSelectionChange): boolean { + if (!event.isUserInput) { + return false; + } + this.enterHandledByRow = true; + return true; + } + + /** + * Enter in the field opens the search page, unless a row has just acted on this same press. + * The flag is also cleared on input, since a pointer selection sets it with no keyup to follow + * and would otherwise swallow the next Enter. */ onSearch(): void { - if (this.searchAutoTrigger?.activeOption) { + if (this.enterHandledByRow) { + this.enterHandledByRow = false; return; } this.seeAllResults();