diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index 02d8c6dd0..04ac39566 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -17,7 +17,6 @@ _During the beta period, these restrictions may be relaxed in the event of a mis - Changed the type of component styles from `CSSResult` to `CSSResultGroup` [#828](https://github.com/shoelace-style/shoelace/issues/828) - Fixed a bug in `` where using Left and Right would select the wrong color - Fixed a bug in `` that caused the position to be incorrect on the first show when using `hoist` [#843](https://github.com/shoelace-style/shoelace/issues/843) -- Fixed a bug in `` where setting the `checked` property programmatically would allow multiple radios or radio buttons to be checked - Fixed a bug in `` where the divider was on the wrong side when using `placement="end"` - Fixed a bug in `` that caused nested tab groups to scroll when using `placement="start|end"` [#815](https://github.com/shoelace-style/shoelace/issues/815) - Fixed a bug in `` that caused the target to be lost after a slot change [#831](https://github.com/shoelace-style/shoelace/pull/831) diff --git a/src/components/radio-button/radio-button.test.ts b/src/components/radio-button/radio-button.test.ts index 1df823705..d5947183b 100644 --- a/src/components/radio-button/radio-button.test.ts +++ b/src/components/radio-button/radio-button.test.ts @@ -89,9 +89,8 @@ describe('', () => { form.addEventListener('submit', submitHandler); radio.click(); - await radio.updateComplete; - button.click(); + await waitUntil(() => submitHandler.calledOnce); expect(formData!.get('a')).to.equal('2'); diff --git a/src/components/radio-group/radio-group.ts b/src/components/radio-group/radio-group.ts index 2903dea24..8609806af 100644 --- a/src/components/radio-group/radio-group.ts +++ b/src/components/radio-group/radio-group.ts @@ -3,7 +3,6 @@ import { customElement, property, query, state } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import '../../components/button-group/button-group'; import styles from './radio-group.styles'; -import type SlRadioButton from '../../components/radio-button/radio-button'; import type SlRadio from '../../components/radio/radio'; import type { CSSResultGroup } from 'lit'; @@ -51,6 +50,19 @@ export default class SlRadioGroup extends LitElement { ) as SlRadio[]; } + handleRadioClick(event: MouseEvent) { + const target = event.target as HTMLElement; + const checkedRadio = target.closest(RADIO_CHILDREN.map(selector => `${selector}:not([disabled])`).join(',')); + + if (checkedRadio) { + const radios = this.getAllRadios(); + radios.forEach(radio => { + radio.checked = radio === checkedRadio; + radio.input.tabIndex = radio === checkedRadio ? 0 : -1; + }); + } + } + handleKeyDown(event: KeyboardEvent) { if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) { const radios = this.getAllRadios().filter(radio => !radio.disabled); @@ -77,19 +89,6 @@ export default class SlRadioGroup extends LitElement { } } - handleRadioChange(event: CustomEvent) { - const target = event.target as SlRadio | SlRadioButton; - - if (RADIO_CHILDREN.includes(target.tagName.toLowerCase())) { - if (target.checked) { - this.getAllRadios().forEach(radio => { - radio.checked = radio === target; - radio.input.tabIndex = radio === target ? 0 : -1; - }); - } - } - } - handleSlotChange() { const radios = this.getAllRadios(); const checkedRadio = radios.find(radio => radio.checked); @@ -109,7 +108,9 @@ export default class SlRadioGroup extends LitElement { } render() { - const defaultSlot = html` `; + const defaultSlot = html` + + `; return html`
${this.label} diff --git a/src/components/radio/radio.test.ts b/src/components/radio/radio.test.ts index 92f4bf3f4..8d0ef26f3 100644 --- a/src/components/radio/radio.test.ts +++ b/src/components/radio/radio.test.ts @@ -90,9 +90,8 @@ describe('', () => { form.addEventListener('submit', submitHandler); radio.click(); - await radio.updateComplete; - button.click(); + await waitUntil(() => submitHandler.calledOnce); expect(formData!.get('a')).to.equal('2');