Skip to content

Commit

Permalink
refactor: use utrecht listbox for all combobox styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Yolijn committed Dec 23, 2024
1 parent be851d5 commit 7a8db61
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export {
Icon,
RadioButton,
LinkButton,
Listbox,
ListboxOption,
AlertDialog,
Article,
PreserveData,
Expand Down
54 changes: 28 additions & 26 deletions src/components/ui/AddressCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ import {
ComboboxOption,
ComboboxOptions,
} from '@headlessui/react'
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react'
import React, {
Dispatch,
Fragment,
SetStateAction,
useEffect,
useState,
} from 'react'
import { useConfig } from '@/hooks/useConfig'
import { getSuggestedAddresses } from '@/services/location/address'
import { StatusText } from '@/components/index'
import {
Listbox,
ListboxOption,
StatusText,
} from '@/components/index'
// Import the Select Combobox component for the side-effects of injecting CSS
// for related components, such as Textbox and Listbox.
import '@utrecht/select-combobox-react/dist/css'
Expand Down Expand Up @@ -72,7 +82,7 @@ export const AddressCombobox = ({
}

getAddressOptions()
}, [query])
}, [config, query])

const onChangeAddress = (selectedAddress: Address) => {
if (!selectedAddress) {
Expand Down Expand Up @@ -124,30 +134,22 @@ export const AddressCombobox = ({
autoComplete={'off'}
/>
{!loading && (
<ComboboxOptions
anchor="bottom"
className="address-listbox utrecht-listbox utrecht-listbox--html-div fixed z-[9999] pointer-events-auto"
>
<div className={'utrecht-listbox__list'}>
{addressOptions.length > 0 ? (
addressOptions.map((address) => (
<ComboboxOption
key={address.id}
value={address}
className="utrecht-listbox__option data-[focus]:bg-blue-100 !px-3 !py-1"
>
{address.weergave_naam}
</ComboboxOption>
))
) : (
<ComboboxOption
value=""
className="!px-3 !py-1 utrecht-listbox--disabled"
>
<StatusText>{t('no_results')}</StatusText>
<ComboboxOptions as={Listbox} anchor="bottom">
{addressOptions.length > 0 ? (
addressOptions.map((address) => (
<ComboboxOption key={address.id} value={address} as={Fragment}>
{({ focus }) => (
<ListboxOption active={focus}>
{address.weergave_naam}
</ListboxOption>
)}
</ComboboxOption>
)}
</div>
))
) : (
<ComboboxOption value="" as={ListboxOption} disabled>
<StatusText>{t('no_results')}</StatusText>
</ComboboxOption>
)}
</ComboboxOptions>
)}
</Combobox>
Expand Down

0 comments on commit 7a8db61

Please sign in to comment.