Skip to content

Commit

Permalink
fix: always include suggestions popup in the DOM (#3860)
Browse files Browse the repository at this point in the history
But hide them when needed.
This will ensure the DOM element referenced by the aria-controls always
exists.

That's (kind of) what Google is doing

KIT-3125
  • Loading branch information
louis-bompart authored Apr 30, 2024
1 parent d94f9e0 commit c13d91f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function getPopupAttributes(props: Required<Props>['popup']) {
autocomplete: 'off',
autocapitalize: 'off',
autocorrect: 'off',
'aria-activedescendant': props.activeDescendant,
...(props.activeDescendant && {
'aria-activedescendant': props.activeDescendant,
}),
'aria-expanded': `${props.hasSuggestions && props.expanded}`,
'aria-autocomplete': 'both',
'aria-haspopup': 'true',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function getPopupAttributes(props: Required<Props>['popup']) {
autocomplete: 'off',
autocapitalize: 'off',
autocorrect: 'off',
'aria-activedescendant': props.activeDescendant,
...(props.activeDescendant && {
'aria-activedescendant': props.activeDescendant,
}),
'aria-expanded': `${props.hasSuggestions && props.expanded}`,
'aria-autocomplete': 'both',
'aria-haspopup': 'true',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ export class AtomicInsightSearchBox {
}`}
role="application"
aria-label={this.bindings.i18n.t('search-suggestions-single-list')}
aria-activedescendant={this.suggestionManager.activeDescendant}
{...(this.suggestionManager.activeDescendant && {
'aria-activedescendant': this.suggestionManager.activeDescendant,
})}
>
{this.renderPanel(
this.suggestionManager.allSuggestionElements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,15 @@ export class AtomicSearchBox implements InitializableComponent<Bindings> {
);
}

private renderSuggestions() {
if (!this.suggestionManager.hasSuggestions) {
return null;
}
private get shouldShowSuggestions() {
return (
this.suggestionManager.hasSuggestions &&
this.isExpanded &&
!this.isSearchDisabledForEndUser(this.searchBoxState.value)
);
}

private renderSuggestions() {
return (
<div
id={`${this.id}-popup`}
Expand All @@ -562,19 +566,17 @@ export class AtomicSearchBox implements InitializableComponent<Bindings> {
: 'suggestions-single-list'
}`}
class={`flex w-full z-10 absolute left-0 top-full rounded-md bg-background border border-neutral ${
this.suggestionManager.hasSuggestions &&
this.isExpanded &&
!this.isSearchDisabledForEndUser(this.searchBoxState.value)
? ''
: 'hidden'
this.shouldShowSuggestions ? '' : 'hidden'
}`}
role="application"
aria-label={this.bindings.i18n.t(
this.suggestionManager.isDoubleList
? 'search-suggestions-double-list'
: 'search-suggestions-single-list'
)}
aria-activedescendant={this.suggestionManager.activeDescendant}
{...(this.suggestionManager.activeDescendant && {
'aria-activedescendant': this.suggestionManager.activeDescendant,
})}
>
{this.renderPanel(
'left',
Expand Down

0 comments on commit c13d91f

Please sign in to comment.