Last active
June 22, 2022 13:39
-
-
Save dorthrithil/9124bb793793c1b2d2cb29894394a07b to your computer and use it in GitHub Desktop.
Reset search text of Clarity Comboboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Directive, OnInit} from '@angular/core'; | |
import {ClrCombobox} from '@clr/angular'; | |
/** | |
* Utility directive to add a missing feature to Clarity comboboxes: Resetting the combobox search text after a | |
* selection. Clarity didn't add it for a11y reasons - for apps that don't need to worry about this in such a strct way | |
* this directive can help. Attach it to any Clariy Combobox and the searchtext will be set to empty string after the | |
* selection changes. | |
*/ | |
@Directive({ | |
selector: '[appComboboxResetSearchtext]' | |
}) | |
export class ComboboxResetSearchtextDirective implements OnInit { | |
constructor(private host: ClrCombobox<any>) { | |
} | |
/** | |
* Subscribes to combobox selection changes and resets the search texts of the combobox in case of a change. | |
*/ | |
ngOnInit() { | |
this.host.clrSelectionChange.subscribe(() => { | |
this.host.searchText = ''; | |
(this.host as any).toggleService.open = false; // Avoid delay before options close, hack type to access private | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment