Browse Source

fix(iot-hub): let the keyboard reach every row of the search popup

The popup keeps focus in the input and walks its rows with an active-descendant key
manager, which only knows about options. A section header written as a span with
role="button" and tabindex="0" is therefore unreachable: the arrow keys skip it, its
keyup.enter can never fire because it can never hold focus, and Tab does not help
since leaving the input closes the panel. That header is the only way from the popup
into a type page, so without a mouse there was no way in at all. The footer had the
same shape, though its action is also on the input's own Enter.

The header also sat inside the group's label element, which is presentational, so the
section's name came out as the header's whole text - "Devices +12 more" - wrapping a
control nobody could operate.

Header and footer are now options like every other row. They take part in arrow
navigation, they read as part of the list, and the group wrapper goes away with the
label it was distorting.

Rows also acted on (click) alone. Pressing Enter on a highlighted result runs
_selectViaInteraction, which is not a DOM click, so the card never opened from the
keyboard. Every row now acts on (onSelectionChange) guarded by isUserInput, one path
for pointer and keyboard both.

Enter in the field needed a guard to go with that: the trigger acts on keydown and
this handler runs on keyup, which the trigger's preventDefault does not stop, so one
Enter would have opened a result and then navigated away from it.
pull/16148/head
dshvaika 2 months ago
parent
commit
c5a3bea6df
  1. 76
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html
  2. 66
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss
  3. 9
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts

76
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.html

@ -85,53 +85,51 @@
</mat-option>
} @else {
@for (group of searchResultGroups; track group.type) {
<mat-optgroup>
<span class="tb-search-popup-group-header" role="button" tabindex="0"
(click)="navigateToSection(group.type)"
(keyup.enter)="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">
{{ 'iot-hub.section-more' | translate:{ count: group.remaining } }}
<mat-icon>chevron_right</mat-icon>
</span>
}
</span>
@for (item of group.items; track item.id) {
<mat-option [value]="searchText" (click)="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>
</div>
} @else {
<div class="tb-search-popup-thumbnail">
@if (getItemImage(item); as imgUrl) {
<img [src]="imgUrl" alt="">
} @else {
<tb-icon class="tb-search-popup-thumb-placeholder">{{ getItemTypeIcon(item.type) }}</tb-icon>
}
</div>
}
<div class="tb-search-popup-text">
<span class="tb-search-popup-name">{{ item.name }}</span>
<span class="tb-search-popup-author">
<mat-icon>person</mat-icon>
{{ item.creatorDisplayName }}
</span>
</div>
</mat-option>
<mat-option class="tb-search-popup-group-header" [value]="searchText"
(onSelectionChange)="$event.isUserInput && 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">
{{ 'iot-hub.section-more' | translate:{ count: group.remaining } }}
<mat-icon>chevron_right</mat-icon>
</span>
}
</mat-optgroup>
</mat-option>
@for (item of group.items; track item.id) {
<mat-option [value]="searchText"
(onSelectionChange)="$event.isUserInput && 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>
</div>
} @else {
<div class="tb-search-popup-thumbnail">
@if (getItemImage(item); as imgUrl) {
<img [src]="imgUrl" alt="">
} @else {
<tb-icon class="tb-search-popup-thumb-placeholder">{{ getItemTypeIcon(item.type) }}</tb-icon>
}
</div>
}
<div class="tb-search-popup-text">
<span class="tb-search-popup-name">{{ item.name }}</span>
<span class="tb-search-popup-author">
<mat-icon>person</mat-icon>
{{ item.creatorDisplayName }}
</span>
</div>
</mat-option>
}
}
}
<div class="tb-search-popup-footer" role="button" tabindex="0"
(click)="seeAllResults()" (keyup.enter)="seeAllResults()">
<mat-option class="tb-search-popup-footer" [value]="searchText"
(onSelectionChange)="$event.isUserInput && seeAllResults()">
@if (searchText?.trim(); as query) {
{{ 'iot-hub.see-results-for' | translate:{ search: query } }}
} @else {
{{ 'iot-hub.see-all-results' | translate }}
}
</div>
</mat-option>
</mat-autocomplete>
</div>
</div>

66
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.scss

@ -220,45 +220,32 @@
0 114px 46px 0 rgba(0, 0, 0, 0.01),
0 178px 50px 0 rgba(0, 0, 0, 0);
// Section group — 12px gap between groups
.mat-mdc-optgroup + .mat-mdc-optgroup .mat-mdc-optgroup-label {
// 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
// "see all" row under the items; six of those on one panel is what this variant avoids.
// Design: 14px Medium, 0.25 tracking, black-tertiary, 4px V / 16px H, 12px above each section.
.mat-mdc-option.tb-search-popup-group-header {
padding: 4px 16px;
min-height: 28px;
margin-top: 12px;
&:first-child {
margin-top: 0;
}
.mdc-list-item__primary-text {
justify-content: space-between;
}
}
// Section title — Design: 14px Medium, 0.25 tracking, black-tertiary, 4px V / 16px H
.mat-mdc-optgroup .mat-mdc-optgroup-label {
padding: 4px 16px;
min-height: 28px;
.tb-search-popup-group-label {
font-size: 14px;
font-weight: 500;
line-height: 20px;
letter-spacing: 0.25px;
color: rgba(0, 0, 0, 0.54);
white-space: nowrap;
.mdc-list-item__primary-text {
font-size: 14px;
font-weight: 500;
line-height: 20px;
letter-spacing: 0.25px;
color: rgba(0, 0, 0, 0.54);
// The header spans the panel so the count can sit against the right edge. Material's own
// label span is only as wide as its text.
width: 100%;
}
}
// Section header — the label IS the link into the type page: title left, how much is not shown
// plus a chevron right. There is deliberately no per-section "see all" row under the items;
// six of those on one panel is what this variant was chosen to avoid.
.tb-search-popup-group-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
width: 100%;
cursor: pointer;
outline: none;
}
.tb-search-popup-group-more {
@ -281,7 +268,7 @@
}
// Item row — Design: 8px V / 16px H, 16px gap, centered
.mat-mdc-optgroup .mat-mdc-option:not(.mat-mdc-option-multiple) {
.mat-mdc-option:not(.mat-mdc-option-multiple) {
padding: 8px 16px;
min-height: auto;
height: auto;
@ -426,26 +413,31 @@
}
// Footer — Design: 40px h, 8px V / 16px H, 1px top border, tb-primary text
.tb-search-popup-footer {
.mat-mdc-option.tb-search-popup-footer {
position: sticky;
bottom: 0;
z-index: 1;
border-top: 1px solid rgba(0, 0, 0, 0.12);
height: 40px;
min-height: 40px;
padding: 8px 16px;
display: flex;
align-items: center;
justify-content: flex-start;
font-size: 14px;
font-weight: 500;
line-height: 20px;
letter-spacing: 0.25px;
color: $tb-primary-color;
cursor: pointer;
background: white;
white-space: nowrap;
&:hover {
.mdc-list-item__primary-text {
justify-content: flex-start;
font: inherit;
letter-spacing: inherit;
color: inherit;
}
&:hover:not(.mdc-list-item--disabled),
&.mat-mdc-option-active:not(.mdc-list-item--disabled) {
background: #f5f5f5;
}
}

9
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts

@ -239,7 +239,16 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
setTimeout(() => this.searchAutoTrigger?.openPanel());
}
/**
* 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.
*/
onSearch(): void {
if (this.searchAutoTrigger?.activeOption) {
return;
}
this.seeAllResults();
}

Loading…
Cancel
Save