File tree Expand file tree Collapse file tree 7 files changed +95
-1
lines changed
src/components-examples/aria/autocomplete Expand file tree Collapse file tree 7 files changed +95
-1
lines changed Original file line number Diff line number Diff line change 77 [(ngModel)] ="query "
88 ngComboboxInput
99 />
10+ < button
11+ class ="example-clear-button "
12+ aria-label ="Clear "
13+ (keydown) ="onKeydown($event) "
14+ (click) ="clear() "
15+ >
16+ < span aria-hidden ="true " class ="example-clear-icon material-symbols-outlined "> close</ span >
17+ </ button >
1018 </ div >
1119
1220 < ng-template ngComboboxPopupContainer >
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ import {FormsModule} from '@angular/forms';
4444 changeDetection : ChangeDetectionStrategy . OnPush ,
4545} )
4646export class AutocompleteAutoSelectExample {
47+ /** The selected value of the combobox. */
48+ listbox = viewChild < Listbox < string > > ( Listbox ) ;
49+
4750 /** The options available in the listbox. */
4851 options = viewChildren < Option < string > > ( Option ) ;
4952
@@ -67,4 +70,19 @@ export class AutocompleteAutoSelectExample {
6770 }
6871 } ) ;
6972 }
73+
74+ /** Clears the query and the listbox value. */
75+ clear ( ) : void {
76+ this . query . set ( '' ) ;
77+ this . listbox ?.( ) ?. values . set ( [ ] ) ;
78+ }
79+
80+ /** Handles keydown events on the clear button. */
81+ onKeydown ( event : KeyboardEvent ) : void {
82+ if ( event . key === 'Enter' ) {
83+ this . clear ( ) ;
84+ this . combobox ?.( ) ?. close ( ) ;
85+ event . stopPropagation ( ) ;
86+ }
87+ }
7088}
Original file line number Diff line number Diff line change 77 [(ngModel)] ="query "
88 ngComboboxInput
99 />
10+ < button
11+ class ="example-clear-button "
12+ aria-label ="Clear "
13+ (keydown) ="onKeydown($event) "
14+ (click) ="clear() "
15+ >
16+ < span aria-hidden ="true " class ="example-clear-icon material-symbols-outlined "> close</ span >
17+ </ button >
1018 </ div >
1119
1220 < ng-template ngComboboxPopupContainer >
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ import {FormsModule} from '@angular/forms';
4444 changeDetection : ChangeDetectionStrategy . OnPush ,
4545} )
4646export class AutocompleteHighlightExample {
47+ /** The selected value of the combobox. */
48+ listbox = viewChild < Listbox < string > > ( Listbox ) ;
49+
4750 /** The options available in the listbox. */
4851 options = viewChildren < Option < string > > ( Option ) ;
4952
@@ -67,4 +70,19 @@ export class AutocompleteHighlightExample {
6770 }
6871 } ) ;
6972 }
73+
74+ /** Clears the query and the listbox value. */
75+ clear ( ) : void {
76+ this . query . set ( '' ) ;
77+ this . listbox ?.( ) ?. values . set ( [ ] ) ;
78+ }
79+
80+ /** Handles keydown events on the clear button. */
81+ onKeydown ( event : KeyboardEvent ) : void {
82+ if ( event . key === 'Enter' ) {
83+ this . clear ( ) ;
84+ this . combobox ?.( ) ?. close ( ) ;
85+ event . stopPropagation ( ) ;
86+ }
87+ }
7088}
Original file line number Diff line number Diff line change 77 [(ngModel)] ="query "
88 ngComboboxInput
99 />
10+ < button
11+ class ="example-clear-button "
12+ aria-label ="Clear "
13+ (keydown) ="onKeydown($event) "
14+ (click) ="clear() "
15+ >
16+ < span aria-hidden ="true " class ="example-clear-icon material-symbols-outlined "> close</ span >
17+ </ button >
1018 </ div >
1119
1220 < ng-template ngComboboxPopupContainer >
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ import {FormsModule} from '@angular/forms';
4444 changeDetection : ChangeDetectionStrategy . OnPush ,
4545} )
4646export class AutocompleteManualExample {
47+ /** The selected value of the combobox. */
48+ listbox = viewChild < Listbox < string > > ( Listbox ) ;
49+
4750 /** The options available in the listbox. */
4851 options = viewChildren < Option < string > > ( Option ) ;
4952
@@ -67,4 +70,19 @@ export class AutocompleteManualExample {
6770 }
6871 } ) ;
6972 }
73+
74+ /** Clears the query and the listbox value. */
75+ clear ( ) : void {
76+ this . query . set ( '' ) ;
77+ this . listbox ?.( ) ?. values . set ( [ ] ) ;
78+ }
79+
80+ /** Handles keydown events on the clear button. */
81+ onKeydown ( event : KeyboardEvent ) : void {
82+ if ( event . key === 'Enter' ) {
83+ this . clear ( ) ;
84+ this . combobox ?.( ) ?. close ( ) ;
85+ event . stopPropagation ( ) ;
86+ }
87+ }
7088}
Original file line number Diff line number Diff line change 2222 width : 13rem ;
2323 font-size : 0.9rem ;
2424 border-radius : var (--mat-sys-corner-extra-small );
25- padding : 0.7rem 0.7 rem 0.7 rem 2.5rem ;
25+ padding : 0.7rem 2.5rem ;
2626 outline-color : var (--mat-sys-primary );
2727 border : 1px solid var (--mat-sys-outline );
2828 background-color : var (--mat-sys-surface );
3838 display : none;
3939}
4040
41+ .example-clear-button {
42+ position : absolute;
43+ right : 0.5rem ;
44+ background-color : transparent;
45+ border : none;
46+ display : flex;
47+ width : 2rem ;
48+ height : 2rem ;
49+ align-items : center;
50+ cursor : pointer;
51+ }
52+
53+ .example-clear-icon {
54+ font-size : 1.25rem ;
55+ }
56+
4157.example-popup {
4258 width : 100% ;
4359 margin-top : 2px ;
You can’t perform that action at this time.
0 commit comments