From 27c509c0d2f08121fb6405f5e435d8860c72648e Mon Sep 17 00:00:00 2001 From: Daniel Sil Date: Thu, 27 Feb 2025 17:03:33 +0100 Subject: [PATCH] fix(ChoiceGroup): the label now renders as a div by default It was rendering as an h4, causing problems with heading hierarchies --- .../src/ChoiceGroup/ChoiceGroup.stories.tsx | 27 +++++++++---------- .../src/ChoiceGroup/index.tsx | 14 ++++++---- .../src/ChoiceGroup/types.d.ts | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/orbit-components/src/ChoiceGroup/ChoiceGroup.stories.tsx b/packages/orbit-components/src/ChoiceGroup/ChoiceGroup.stories.tsx index 161b602202..e59550c125 100644 --- a/packages/orbit-components/src/ChoiceGroup/ChoiceGroup.stories.tsx +++ b/packages/orbit-components/src/ChoiceGroup/ChoiceGroup.stories.tsx @@ -30,7 +30,6 @@ const meta: Meta = { label: "What was the reason for your cancellation?", onlySelectionText: "Only", labelSize: LABEL_SIZES.NORMAL, - labelAs: LABEL_ELEMENTS.H4, error: "", filter: false, onChange: action("onChange"), @@ -59,9 +58,9 @@ type Story = StoryObj; export const Default: Story = { render: args => ( - - - + + + ), @@ -104,9 +103,9 @@ export const Filter: Story = { export const WithError: Story = { render: args => ( - - - + + + ), @@ -153,7 +152,7 @@ export const RenderProp: Story = { }} > - + )} @@ -176,9 +175,9 @@ export const RenderProp: Story = { export const Playground: Story = { render: args => ( - - - + + + ), @@ -191,9 +190,9 @@ export const Rtl: Story = { render: args => ( - - - + + + ), diff --git a/packages/orbit-components/src/ChoiceGroup/index.tsx b/packages/orbit-components/src/ChoiceGroup/index.tsx index e3cf385342..8e35e9f71f 100644 --- a/packages/orbit-components/src/ChoiceGroup/index.tsx +++ b/packages/orbit-components/src/ChoiceGroup/index.tsx @@ -6,7 +6,7 @@ import cx from "clsx"; import Heading from "../Heading"; import type { Type } from "../Heading/types"; import Stack from "../Stack"; -import { LABEL_SIZES, LABEL_ELEMENTS } from "./consts"; +import { LABEL_SIZES } from "./consts"; import Feedback from "./components/Feedback"; import FilterWrapper from "./components/FilterWrapper"; import useRandomId from "../hooks/useRandomId"; @@ -45,7 +45,7 @@ const ChoiceGroup = React.forwardRef( id, label, labelSize = LABEL_SIZES.NORMAL, - labelAs = LABEL_ELEMENTS.H4, + labelAs = "div", error, children, filter, @@ -82,14 +82,18 @@ const ChoiceGroup = React.forwardRef( )} > {label && ( - + {label} )} {typeof children === "function" ? ( children({ - // for now a plain
is all we need, but we're reserving this space in the API - // in case we'll need something more in the future Container: "div", Item: ItemContainer({ filter, onOnlySelection, onlySelectionText, itemProps }), spacing: filter ? "0px" : theme.orbit.space200, diff --git a/packages/orbit-components/src/ChoiceGroup/types.d.ts b/packages/orbit-components/src/ChoiceGroup/types.d.ts index 79634f13a5..0a0464d146 100644 --- a/packages/orbit-components/src/ChoiceGroup/types.d.ts +++ b/packages/orbit-components/src/ChoiceGroup/types.d.ts @@ -6,7 +6,7 @@ import type * as React from "react"; import type * as Common from "../common/types"; export type Size = "normal" | "large"; -type Element = "h2" | "h3" | "h4" | "h5" | "h6"; +type Element = "h2" | "h3" | "h4" | "h5" | "h6" | "div"; export interface Props extends Common.Globals { readonly children: