Skip to content

Commit 4b1a756

Browse files
authored
minor: try to fix firewall rule test flake again (#2993)
try to fix firewall rule test flake
1 parent 867e4da commit 4b1a756

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

app/forms/firewall-rules-common.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ const ProtocolFilters = ({ control }: { control: Control<FirewallRuleValues> })
494494
placeholder=""
495495
validate={icmpCodeValidation}
496496
transform={normalizeDashes}
497+
onKeyDown={(e) => {
498+
if (e.key === KEYS.enter) {
499+
e.preventDefault() // prevent full form submission
500+
submitProtocol(e)
501+
}
502+
}}
497503
/>
498504
)}
499505
</>

app/ui/lib/Combobox.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,16 @@ export const Combobox = ({
213213
onInputChange?.(value)
214214
}}
215215
onKeyDown={(e) => {
216-
// If the caller is using onEnter to override enter behavior, preventDefault
217-
// in order to prevent the containing form from being submitted too. We don't
218-
// need to do this when the combobox is open because that enter keypress is
219-
// already handled internally (selects the highlighted item). So we only do
220-
// this when the combobox is closed.
221-
if (e.key === 'Enter' && onEnter && !open) {
216+
// When the combobox is open, Enter is handled internally by
217+
// Headless UI (selects the highlighted item). When closed,
218+
// we need to prevent the default behavior to avoid submitting
219+
// the containing form. We also considered always preventing
220+
// default on Enter regardless of open status, but it appears
221+
// to break the combobox handling. Headless UI likely checks
222+
// e.defaultPrevented before processing item selection.
223+
if (e.key === 'Enter' && !open) {
222224
e.preventDefault()
223-
onEnter(e)
225+
onEnter?.(e)
224226
}
225227
}}
226228
placeholder={placeholder}

test/e2e/firewall-rules.e2e.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,6 @@ test('can update firewall rule', async ({ page }) => {
456456
await selectOption(page, 'Protocol filters', 'ICMP')
457457
await page.getByRole('combobox', { name: 'ICMP Type' }).fill('3')
458458
await page.getByRole('combobox', { name: 'ICMP Type' }).press('Enter')
459-
460-
// give FF time to process the above enter before moving to the next field
461-
await sleep(300)
462-
463459
await page.getByRole('textbox', { name: 'ICMP Code' }).fill('0')
464460
await page.getByRole('button', { name: 'Add protocol' }).click()
465461

0 commit comments

Comments
 (0)