Browse Source

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.
pull/16148/head
dshvaika 3 months ago
parent
commit
14e3025a24
  1. 36
      ui-ngx/src/app/modules/home/components/iot-hub/_iot-hub-common.scss
  2. 27
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-facet-list.component.scss
  3. 27
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-search.component.scss
  4. 8
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html
  5. 40
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss
  6. 31
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts

36
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);
}
}
}
}

27
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 {

27
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.

8
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) {
<mat-option class="tb-search-popup-group-header" [value]="searchText"
(onSelectionChange)="$event.isUserInput && navigateToSection(group.type)">
(onSelectionChange)="rowSelectedByUser($event) && navigateToSection(group.type)">
<span class="tb-search-popup-group-label">{{ getSearchGroupLabel(group.type) }}</span>
@if (group.remaining > 0) {
<span class="tb-search-popup-group-more">
@ -96,8 +96,8 @@
}
</mat-option>
@for (item of group.items; track item.id) {
<mat-option [value]="searchText"
(onSelectionChange)="$event.isUserInput && openItemDetail(item)">
<mat-option class="tb-search-popup-item" [value]="searchText"
(onSelectionChange)="rowSelectedByUser($event) && openItemDetail(item)">
@if (isCompactType(item.type)) {
<div class="tb-search-popup-icon-square" [style.background]="item.color || '#048ad3'">
<tb-icon class="tb-search-popup-icon-inner">{{ getCompactIcon(item) }}</tb-icon>
@ -123,7 +123,7 @@
}
}
<mat-option class="tb-search-popup-footer" [value]="searchText"
(onSelectionChange)="$event.isUserInput && seeAllResults()">
(onSelectionChange)="rowSelectedByUser($event) && seeAllResults()">
@if (searchText?.trim(); as query) {
{{ 'iot-hub.see-results-for' | translate:{ search: query } }}
} @else {

40
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.<kind> 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 {

31
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<string>();
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();

Loading…
Cancel
Save