@@ -6,6 +6,7 @@ import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsCon
6
6
import { useInputContext } from "../Input/inputContext" ;
7
7
import { Loader } from "../../../loader" ;
8
8
import { BodyShort , Label } from "../../../typography" ;
9
+ import filteredOptionsUtil from "./filtered-options-util" ;
9
10
10
11
const FilteredOptions = ( ) => {
11
12
const {
@@ -18,25 +19,25 @@ const FilteredOptions = () => {
18
19
isLoading,
19
20
isListOpen,
20
21
filteredOptions,
21
- filteredOptionsIndex,
22
- filteredOptionsRef,
22
+ setFilteredOptionsRef,
23
23
isMouseLastUsedInputDevice,
24
24
setIsMouseLastUsedInputDevice,
25
25
isValueNew,
26
- setFilteredOptionsIndex,
27
26
toggleIsListOpen,
27
+ activeDecendantId,
28
+ virtualFocus,
28
29
} = useFilteredOptionsContext ( ) ;
29
30
const { isMultiSelect, selectedOptions, toggleOption } =
30
31
useSelectedOptionsContext ( ) ;
31
32
32
33
return (
33
34
< ul
34
- ref = { filteredOptionsRef }
35
+ ref = { setFilteredOptionsRef }
35
36
className = { cl ( "navds-combobox__list" , {
36
37
"navds-combobox__list--closed" : ! isListOpen ,
37
38
"navds-combobox__list--with-hover" : isMouseLastUsedInputDevice ,
38
39
} ) }
39
- id = { ` ${ id } -filtered-options` }
40
+ id = { filteredOptionsUtil . getFilteredOptionsId ( id ) }
40
41
role = "listbox"
41
42
tabIndex = { - 1 }
42
43
>
@@ -45,7 +46,8 @@ const FilteredOptions = () => {
45
46
className = "navds-combobox__list-item--loading"
46
47
role = "option"
47
48
aria-selected = { false }
48
- id = { `${ id } -is-loading` }
49
+ id = { filteredOptionsUtil . getIsLoadingId ( id ) }
50
+ data-no-focus = "true"
49
51
>
50
52
< Loader aria-label = "Søker..." />
51
53
</ li >
@@ -54,8 +56,12 @@ const FilteredOptions = () => {
54
56
< li
55
57
tabIndex = { - 1 }
56
58
onMouseMove = { ( ) => {
57
- if ( filteredOptionsIndex !== - 1 ) {
58
- setFilteredOptionsIndex ( - 1 ) ;
59
+ if (
60
+ activeDecendantId !== filteredOptionsUtil . getAddNewOptionId ( id )
61
+ ) {
62
+ virtualFocus . moveFocusToElement (
63
+ filteredOptionsUtil . getAddNewOptionId ( id )
64
+ ) ;
59
65
setIsMouseLastUsedInputDevice ( true ) ;
60
66
}
61
67
} }
@@ -64,10 +70,10 @@ const FilteredOptions = () => {
64
70
if ( ! isMultiSelect && ! selectedOptions . includes ( value ) )
65
71
toggleIsListOpen ( false ) ;
66
72
} }
67
- id = { ` ${ id } -combobox-new-option` }
73
+ id = { filteredOptionsUtil . getAddNewOptionId ( id ) }
68
74
className = { cl ( "navds-combobox__list-item__new-option" , {
69
75
"navds-combobox__list-item__new-option--focus" :
70
- filteredOptionsIndex === - 1 ,
76
+ activeDecendantId === filteredOptionsUtil . getAddNewOptionId ( id ) ,
71
77
} ) }
72
78
role = "option"
73
79
aria-selected = { false }
@@ -86,24 +92,30 @@ const FilteredOptions = () => {
86
92
className = "navds-combobox__list-item__no-options"
87
93
role = "option"
88
94
aria-selected = { false }
89
- id = { `${ id } -no-hits` }
95
+ id = { filteredOptionsUtil . getNoHitsId ( id ) }
96
+ data-no-focus = "true"
90
97
>
91
98
Ingen søketreff
92
99
</ li >
93
100
) }
94
- { filteredOptions . map ( ( option , index ) => (
101
+ { filteredOptions . map ( ( option ) => (
95
102
< li
96
103
className = { cl ( "navds-combobox__list-item" , {
97
- "navds-combobox__list-item--focus" : index === filteredOptionsIndex ,
104
+ "navds-combobox__list-item--focus" :
105
+ activeDecendantId === filteredOptionsUtil . getOptionId ( id , option ) ,
98
106
"navds-combobox__list-item--selected" :
99
107
selectedOptions . includes ( option ) ,
100
108
} ) }
101
- id = { ` ${ id } -option- ${ option . replace ( " " , "-" ) } ` }
109
+ id = { filteredOptionsUtil . getOptionId ( id , option ) }
102
110
key = { option }
103
111
tabIndex = { - 1 }
104
112
onMouseMove = { ( ) => {
105
- if ( filteredOptionsIndex !== index ) {
106
- setFilteredOptionsIndex ( index ) ;
113
+ if (
114
+ activeDecendantId !== filteredOptionsUtil . getOptionId ( id , option )
115
+ ) {
116
+ virtualFocus . moveFocusToElement (
117
+ filteredOptionsUtil . getOptionId ( id , option )
118
+ ) ;
107
119
setIsMouseLastUsedInputDevice ( true ) ;
108
120
}
109
121
} }
0 commit comments