Drop down with a disabled option
A drop down with a disabled option.
Note that the disabled option can still be focused. If you didn't want this you can modify the skipOption
prop. However, this would mean screen-readers would be unable to see the disabled option.
import { useRef, useState } from 'react';
import { DropDown } from '@citizensadvice/react-combo-boxes';
const options = [
{ label: 'Apple' },
{ label: 'Orange' },
{ label: 'Lemon', disabled: true },
{ label: 'Raspberry' },
{ label: 'Strawberry' },
];
export function Example() {
const [value, setValue] = useState(null);
const ref = useRef();
return (
<>
<div
className="label"
onClick={() => ref.current.focus()}
id="drop-down-label"
>
Drop down
</div>
<DropDown
ref={ref}
id="drop-down"
aria-labelledby="drop-down-label"
value={value}
onValue={setValue}
options={options}
/>
<label htmlFor="output">Current value</label>
<output
htmlFor="drop-down"
id="output"
>
{JSON.stringify(value, undefined, ' ')}
</output>
</>
);
}