From ca9beebaeac7eaed8079c010a86a78926b00147f Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 22 Mar 2025 13:03:20 -0700 Subject: [PATCH] fix(radio-tile): allow standalone `RadioTile` usage (#2136) Although `RadioTile` is meant to be used inside a `TileGroup`, it feels unpolished for standalone usage to crash due to a missing parent context. This fixes `RadioTile` to fail open by providing a no-op `add: () => {}` when `TileGroup` context is not found. --- src/Tile/RadioTile.svelte | 1 + tests/RadioTile/RadioTile.test.ts | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tile/RadioTile.svelte b/src/Tile/RadioTile.svelte index 5e960c89..8ded1870 100644 --- a/src/Tile/RadioTile.svelte +++ b/src/Tile/RadioTile.svelte @@ -36,6 +36,7 @@ const { add, update, selectedValue, groupName, groupRequired } = getContext( "TileGroup", ) ?? { + add: () => {}, groupName: readable(undefined), groupRequired: readable(undefined), selectedValue: readable(checked ? value : undefined), diff --git a/tests/RadioTile/RadioTile.test.ts b/tests/RadioTile/RadioTile.test.ts index 351c01dc..9697654a 100644 --- a/tests/RadioTile/RadioTile.test.ts +++ b/tests/RadioTile/RadioTile.test.ts @@ -94,8 +94,7 @@ describe("RadioTile", () => { expect(radioTileLabel).toHaveAttribute("for", "custom-id"); }); - // TODO(bug): support standalone radio tile. - it.skip("should handle custom name", () => { + it("should handle custom name", () => { render(RadioTileSingle); expect(screen.getByRole("radio")).toHaveAttribute("name", "custom-name");