File tree Expand file tree Collapse file tree 2 files changed +31
-14
lines changed Expand file tree Collapse file tree 2 files changed +31
-14
lines changed Original file line number Diff line number Diff line change 35
35
' smui-autocomplete__menu' : true ,
36
36
})}
37
37
managed
38
- bind:open ={menuOpen }
38
+ neverRestoreFocus
39
+ open ={focused &&
40
+ (text !== ' ' || showMenuWithNoInput ) &&
41
+ (loading ||
42
+ (! combobox && ! (matches .length === 1 && matches [0 ] === value )) ||
43
+ (combobox &&
44
+ !! matches .length &&
45
+ ! (matches .length === 1 && matches [0 ] === value )))}
39
46
bind:anchorElement ={element }
40
47
anchor ={menu$anchor }
41
48
anchorCorner ={menu$anchorCorner }
203
210
let focusedIndex = - 1 ;
204
211
let focusedItem: SMUIListItemAccessor | undefined = undefined ;
205
212
206
- $ : menuOpen =
207
- focused &&
208
- (text !== ' ' || showMenuWithNoInput ) &&
209
- (loading ||
210
- (! combobox && ! (matches .length === 1 && matches [0 ] === value )) ||
211
- (combobox &&
212
- !! matches .length &&
213
- ! (matches .length === 1 && matches [0 ] === value )));
214
-
215
213
let previousText = text ;
216
214
$ : if (previousText !== text ) {
217
215
if (! combobox && value != null && getOptionLabel (value ) !== text ) {
218
216
deselectOption (value , false );
219
217
}
220
218
221
- performSearch ();
222
-
223
- previousText = text ;
219
+ // Only when we're focused do we need to perform a search.
220
+ if (focused ) {
221
+ performSearch ();
222
+ previousText = text ;
223
+ }
224
224
}
225
225
226
226
$ : if (options ) {
420
420
.map ((itemAccessor ) => itemAccessor .element )
421
421
.indexOf (event .relatedTarget as Element ) !== - 1
422
422
) {
423
+ // Wait until the item is selected.
424
+ element .addEventListener (
425
+ ' SMUIAutocomplete:selected' ,
426
+ () => {
427
+ // Then clear the focus.
428
+ focusedIndex = - 1 ;
429
+ focused = false ;
430
+ },
431
+ { once: true }
432
+ );
423
433
return ;
424
434
}
425
435
426
- // Else, clear the currently focused item and mark as not focused .
436
+ // Clear the focus and input .
427
437
focusedIndex = - 1 ;
428
438
focused = false ;
429
439
Original file line number Diff line number Diff line change 63
63
* menu during positioning calculations.
64
64
*/
65
65
openBottomBias? : number ;
66
+ /**
67
+ * Set this to true to never restore focus to the previously focused element
68
+ * when the menu is closed.
69
+ */
70
+ neverRestoreFocus? : boolean ;
66
71
};
67
72
type $$Props = OwnProps &
68
73
SmuiAttrs <
101
106
export let maxHeight = 0 ;
102
107
export let horizontallyCenteredOnViewport = false ;
103
108
export let openBottomBias = 0 ;
109
+ export let neverRestoreFocus = false ;
104
110
105
111
let element: HTMLDivElement ;
106
112
let instance: MDCMenuSurfaceFoundation ;
235
241
},
236
242
restoreFocus : () => {
237
243
if (
244
+ ! neverRestoreFocus &&
238
245
(! element || element .contains (document .activeElement )) &&
239
246
previousFocus &&
240
247
document .contains (previousFocus ) &&
You can’t perform that action at this time.
0 commit comments