Skip to content

Commit ff72a5f

Browse files
committed
fix radio group tests
1 parent c1fc828 commit ff72a5f

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

packages/web-components/src/radio-group/radio-group.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,16 @@ test.describe('RadioGroup', () => {
492492
const { element } = fastPage;
493493
const radios = element.locator('fluent-radio');
494494

495-
await fastPage.setTemplate({
496-
innerHTML: /* html */ `
495+
await fastPage.setTemplate(/* html */ `
496+
<button data-testid="before">before</button>
497+
<fluent-radio-group>
497498
<fluent-radio></fluent-radio>
498499
<fluent-radio></fluent-radio>
499500
<fluent-radio></fluent-radio>
500-
`,
501-
});
501+
</fluent-radio-group>
502+
`);
502503

504+
await page.getByTestId('before').focus();
503505
await page.keyboard.press('Tab');
504506

505507
await expect(radios.nth(0)).toBeFocused();

packages/web-components/src/radio-group/radio-group.template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { RadioGroup } from './radio-group.js';
44
export function radioGroupTemplate<T extends RadioGroup>(): ElementViewTemplate<T> {
55
return html<T>`
66
<template
7-
focusgroup="radiogroup"
7+
focusgroup="radiogroup wrap"
88
@disabled="${(x, c) => x.disabledRadioHandler(c.event as CustomEvent)}"
99
@change="${(x, c) => x.changeHandler(c.event as Event)}"
1010
@click="${(x, c) => x.clickHandler(c.event as MouseEvent)}"

packages/web-components/src/radio-group/radio-group.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,16 @@ export class RadioGroup extends FASTElement {
431431
*/
432432
public focusinHandler(e: FocusEvent): boolean | void {
433433
if (!this.disabled) {
434+
// Uncheck the checked disabled radio, if any.
435+
this.radios?.forEach(radio => {
436+
if (radio.disabled && radio.checked) {
437+
radio.checked = false;
438+
}
439+
});
440+
434441
const index = this.enabledRadios.indexOf(e.target as Radio);
435442
if (index > -1) {
436-
this.checkRadio(index);
443+
this.checkRadio(index, true);
437444
}
438445
}
439446

packages/web-components/test/harness/src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ if (!CSS.supports('anchor-name: --foo')) {
66
});
77
}
88

9+
if (!('focusgroup' in HTMLElement.prototype)) {
10+
import('../../../public/focusgroup-polyfill.js').then(({ polyfill }) => {
11+
Object.defineProperty(window, 'FOCUSGROUP_POLYFILL', {
12+
value: polyfill,
13+
});
14+
});
15+
}
16+
917
import { webLightTheme } from '@fluentui/tokens';
1018
import { setTheme } from '../../../src/theme/set-theme.js';
1119
import '../../../src/index-rollup.js';

0 commit comments

Comments
 (0)