11import { mdiCheck , mdiClose , mdiPlus } from "@mdi/js"
22import { Key } from "@solid-primitives/keyed"
33import type { Accessor } from "solid-js"
4- import { createEffect , createSignal , For , mergeProps , onMount } from "solid-js"
4+ import { For , mergeProps } from "solid-js"
55import { ct0 , ct1 } from "~ui/i18n/ct0"
66import { t4multiselect } from "~ui/input/select/t4multiselect"
77import { buttonVariant } from "~ui/interactive/button/buttonCva"
@@ -119,67 +119,14 @@ interface OptionListProps extends HasId, MayHaveInnerClass {
119119}
120120
121121function OptionList ( p : OptionListProps ) {
122- const getOptions = p . getOptions
123- const options = getOptions ( )
124- const [ focusedIndex , setFocusedIndex ] = createSignal ( - 1 )
125-
126- createEffect ( ( ) => {
127- const idx = focusedIndex ( )
128- if ( idx >= 0 ) {
129- setTimeout ( ( ) => {
130- const el = document . getElementById ( `${ p . id } -option-${ idx } ` )
131- el ?. focus ( )
132- } , 0 )
133- }
134- } )
135-
136- onMount ( ( ) => {
137- if ( options . length > 0 ) {
138- setFocusedIndex ( 0 )
139- }
140- } )
141-
142- const handleKeyDown = ( e : KeyboardEvent ) => {
143- const opts = getOptions ( )
144- switch ( e . key ) {
145- case "ArrowDown" :
146- e . preventDefault ( )
147- setFocusedIndex ( ( prev ) => ( prev + 1 ) % opts . length )
148- break
149- case "ArrowUp" :
150- e . preventDefault ( )
151- setFocusedIndex ( ( prev ) => ( prev - 1 + opts . length ) % opts . length )
152- break
153- case "Enter" :
154- case " " :
155- e . preventDefault ( )
156- if ( focusedIndex ( ) >= 0 ) {
157- const option = opts [ focusedIndex ( ) ] !
158- toggleOption ( { option, valueSignal : p . valueSignal , valueText : p . valueText } )
159- }
160- break
161- }
162- }
163-
164- if ( options . length === 0 ) {
165- return < NoItems class = { p . noItemsClass } />
166- }
167-
168122 return (
169- < div
170- role = "listbox"
171- aria-multiselectable = "true"
172- onKeyDown = { handleKeyDown }
173- class = { getInnerClass ( options . length , p . innerClass ) }
174- >
175- < For each = { options } >
123+ < div role = "listbox" aria-multiselectable = "true" class = { getInnerClass ( p . getOptions ( ) . length , p . innerClass ) } >
124+ < For each = { p . getOptions ( ) } fallback = { < NoItems class = { p . noItemsClass } /> } >
176125 { ( option , index ) => (
177126 < ListOption
178127 id = { p . id }
179128 option = { option }
180129 index = { index ( ) }
181- focusedIndex = { focusedIndex ( ) }
182- setFocusedIndex = { setFocusedIndex }
183130 valueSignal = { p . valueSignal }
184131 valueText = { p . valueText }
185132 listOptionClass = { p . listOptionClass }
@@ -202,26 +149,22 @@ function getInnerClass(optionAmount: number, innerClass?: string): string {
202149
203150interface ListOptionProps extends HasId , MultiselectOptionState {
204151 index : number
205- focusedIndex : number
206- setFocusedIndex : ( v : number ) => void
207152 listOptionClass ?: string
208153}
209154
210155function ListOption ( p : ListOptionProps ) {
211156 const label = ( ) => ( p . valueText ? p . valueText ( p . option ) : p . option )
212157 return (
213158 < ButtonIcon
214- id = { `${ p . id } -option-${ p . index } ` }
215- tabIndex = { p . focusedIndex === p . index ? 0 : - 1 }
159+ // id={`${p.id}-option-${p.index}`}
216160 role = "option"
217161 aria-selected = { optionIsSelected ( p ) }
218162 iconRight = { optionIsSelected ( p ) ? mdiCheck : undefined }
219163 onClick = { ( ) => {
220164 toggleOption ( p )
221- p . setFocusedIndex ( p . index )
222165 } }
223166 variant = { buttonVariant . ghost }
224- class = { classMerge ( "justify-start" , p . focusedIndex === p . index ? "ring-2 ring-blue-500" : "" , p . listOptionClass ) }
167+ class = { classMerge ( "justify-start" , p . listOptionClass ) }
225168 >
226169 { label ( ) }
227170 </ ButtonIcon >
0 commit comments