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.
This commit is contained in:
Eric Liu 2025-03-22 13:03:20 -07:00 committed by GitHub
commit ca9beebaea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -36,6 +36,7 @@
const { add, update, selectedValue, groupName, groupRequired } = getContext( const { add, update, selectedValue, groupName, groupRequired } = getContext(
"TileGroup", "TileGroup",
) ?? { ) ?? {
add: () => {},
groupName: readable(undefined), groupName: readable(undefined),
groupRequired: readable(undefined), groupRequired: readable(undefined),
selectedValue: readable(checked ? value : undefined), selectedValue: readable(checked ? value : undefined),

View file

@ -94,8 +94,7 @@ describe("RadioTile", () => {
expect(radioTileLabel).toHaveAttribute("for", "custom-id"); expect(radioTileLabel).toHaveAttribute("for", "custom-id");
}); });
// TODO(bug): support standalone radio tile. it("should handle custom name", () => {
it.skip("should handle custom name", () => {
render(RadioTileSingle); render(RadioTileSingle);
expect(screen.getByRole("radio")).toHaveAttribute("name", "custom-name"); expect(screen.getByRole("radio")).toHaveAttribute("name", "custom-name");