Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use utrecht listbox for all combobox styling #332

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading