File tree Expand file tree Collapse file tree 4 files changed +22
-15
lines changed
apps/website/src/routes/docs/headless/select
packages/kit-headless/src/components/select Expand file tree Collapse file tree 4 files changed +22
-15
lines changed Original file line number Diff line number Diff line change @@ -508,15 +508,15 @@ test.describe('Props', () => {
508
508
await expect ( await getValue ( ) ) . toEqual ( 'Jessie' ) ;
509
509
} ) ;
510
510
511
- // test(`GIVEN an uncontrolled select with a value prop on the root component
512
- // WHEN the value data matches the fourth option
513
- // THEN the fourth option should have aria-selected set to true`, async ({
514
- // page,
515
- // }) => {
516
- // const { getValue, getOptions } = await setup(page, 'select-uncontrolled-test');
517
-
518
- // await expect(await getValue()).toEqual('Jessie');
519
- // const options = await getOptions();
520
- // await expect(await options[3]).toBeSelected( );
521
- // });
511
+ test ( `GIVEN an uncontrolled select with a value prop on the root component
512
+ WHEN the value data matches the fourth option
513
+ THEN the fourth option should have data-highlighted set to true` , async ( {
514
+ page,
515
+ } ) => {
516
+ const { getValue, getOptions } = await setup ( page , 'select-uncontrolled-test' ) ;
517
+
518
+ await expect ( await getValue ( ) ) . toEqual ( 'Jessie' ) ;
519
+ const options = await getOptions ( ) ;
520
+ await expect ( await options [ 3 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
521
+ } ) ;
522
522
} ) ;
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { SelectOption } from './select-option';
10
10
export const Select : FunctionComponent < SelectProps > = ( props ) => {
11
11
const { children : myChildren , ...rest } = props ;
12
12
let valuePropIndex = 0 ;
13
-
13
+ const isDisabledArr = [ ] ;
14
14
const childrenToProcess = (
15
15
Array . isArray ( myChildren ) ? [ ...myChildren ] : [ myChildren ]
16
16
) as Array < JSXNode > ;
@@ -49,11 +49,17 @@ export const Select: FunctionComponent<SelectProps> = (props) => {
49
49
if ( child . props . children === props . value ) {
50
50
valuePropIndex = currentIndex ;
51
51
}
52
-
52
+ isDisabledArr . push ( child . props . disabled ) ;
53
53
currentIndex ++ ;
54
54
}
55
55
}
56
56
}
57
+
58
+ // TODO: will have problems if all options are disabled
59
+ if ( isDisabledArr [ valuePropIndex ] === true ) {
60
+ valuePropIndex = isDisabledArr . findIndex ( ( isDisabled ) => isDisabled === false ) ;
61
+ }
62
+
57
63
return (
58
64
< SelectImpl { ...rest } valuePropIndex = { valuePropIndex } >
59
65
{ props . children }
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export const SelectTrigger = component$<SelectTriggerProps>((props) => {
31
31
const shouldOpen = ! context . isListboxOpenSig . value && openKeys . includes ( e . key ) ;
32
32
const shouldClose = context . isListboxOpenSig . value && closedKeys . includes ( e . key ) ;
33
33
34
+ // TODO: refactor with data grabbed from inline component
34
35
const options : OptionsType = context . optionRefsArray . value . map ( ( option ) => {
35
36
if ( option . value === undefined ) {
36
37
throw new Error ( 'Qwik UI: internal select option is undefined' ) ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export type SelectProps = PropsOf<'div'> & {
14
14
value ?: string ;
15
15
16
16
// when a value is passed, we check if it's an actual option value, and get its index at pre-render time.
17
- valuePropIndex : number ;
17
+ valuePropIndex ? : number ;
18
18
} ;
19
19
20
20
/* root component in select-inline.tsx */
@@ -31,7 +31,7 @@ export const SelectImpl = component$<SelectProps>((props) => {
31
31
const selectedIndexSig = useSignal < number | null > ( null ) ;
32
32
const selectedOptionRef = useSignal < HTMLLIElement | null > ( null ) ;
33
33
const isListboxOpenSig = useSignal < boolean > ( false ) ;
34
- const highlightedIndexSig = useSignal < number | null > ( props . valuePropIndex ) ;
34
+ const highlightedIndexSig = useSignal < number | null > ( props . valuePropIndex ?? null ) ;
35
35
36
36
useTask$ ( function deriveSelectedRef ( { track } ) {
37
37
track ( ( ) => selectedIndexSig . value ) ;
You can’t perform that action at this time.
0 commit comments