Skip to content

Commit 0a47097

Browse files
authored
Fix listbox IDs; better link labels to inputs (#2492)
1 parent 48f3bca commit 0a47097

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

app/ui/lib/Listbox.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
*/
88
import {
99
Listbox as HListbox,
10-
Label,
1110
ListboxButton,
1211
ListboxOption,
1312
ListboxOptions,
1413
} from '@headlessui/react'
1514
import cn from 'classnames'
16-
import { type ReactNode, type Ref } from 'react'
15+
import { useId, type ReactNode, type Ref } from 'react'
1716

1817
import { SelectArrows6Icon } from '@oxide/design-system/icons/react'
1918

@@ -68,6 +67,7 @@ export const Listbox = <Value extends string = string>({
6867
const noItems = !isLoading && items.length === 0
6968
const isDisabled = disabled || noItems
7069
const zIndex = usePopoverZIndex()
70+
const id = useId()
7171

7272
return (
7373
<div className={cn('relative', className)}>
@@ -83,13 +83,20 @@ export const Listbox = <Value extends string = string>({
8383
<>
8484
{label && (
8585
<div className="mb-2">
86-
<FieldLabel id={``} as="div" optional={!required && !hideOptionalTag}>
87-
<Label>{label}</Label>
86+
<FieldLabel
87+
id={`${id}-label`}
88+
htmlFor={id}
89+
optional={!required && !hideOptionalTag}
90+
>
91+
{label}
8892
</FieldLabel>
89-
{description && <TextInputHint id={``}>{description}</TextInputHint>}
93+
{description && (
94+
<TextInputHint id={`${id}-help-text`}>{description}</TextInputHint>
95+
)}
9096
</div>
9197
)}
9298
<ListboxButton
99+
id={id}
93100
name={name}
94101
className={cn(
95102
`flex h-10 w-full items-center justify-between rounded border text-sans-md`,

test/e2e/floating-ip-create.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ test('can detach and attach a floating IP', async ({ page }) => {
8383
// Now click back to floating IPs and reattach it to db1
8484
await page.getByRole('link', { name: 'Floating IPs' }).click()
8585
await clickRowAction(page, 'cola-float', 'Attach')
86-
await page.getByRole('button', { name: 'Select an instance' }).click()
86+
await page.getByLabel('Instance').click()
8787
await page.getByRole('option', { name: 'db1' }).click()
8888

8989
await page.getByRole('button', { name: 'Attach' }).click()

test/e2e/instance-create.e2e.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,10 @@ test('does not attach an ephemeral IP when the checkbox is unchecked', async ({
398398

399399
test('attaches a floating IP; disables button when no IPs available', async ({ page }) => {
400400
const attachFloatingIpButton = page.getByRole('button', { name: 'Attach floating IP' })
401-
const selectFloatingIpButton = page.getByRole('button', { name: 'Select a floating ip' })
401+
const dialog = page.getByRole('dialog')
402+
const selectFloatingIpButton = dialog.getByRole('button', { name: 'Floating IP' })
402403
const rootbeerFloatOption = page.getByRole('option', { name: 'rootbeer-float' })
403-
const attachButton = page.getByRole('button', { name: 'Attach', exact: true })
404+
const attachButton = dialog.getByRole('button', { name: 'Attach', exact: true })
404405

405406
const instanceName = 'with-floating-ip'
406407
await page.goto('/projects/mock-project/instances-new')

test/e2e/instance-networking.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ test('Instance networking tab — floating IPs', async ({ page }) => {
129129
// Select the 'rootbeer-float' option
130130
const dialog = page.getByRole('dialog')
131131
// TODO: this "select the option" syntax is awkward; it's working, but I suspect there's a better way
132-
await dialog.getByRole('button', { name: 'Select a floating IP' }).click()
132+
await dialog.getByLabel('Floating IP').click()
133133
await page.keyboard.press('ArrowDown')
134134
await page.keyboard.press('Enter')
135135
// await dialog.getByRole('button', { name: 'rootbeer-float' }).click()

0 commit comments

Comments
 (0)