@purpurds/radio-card-group 6.6.0 → 6.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LICENSE.txt +3 -3
- package/dist/radio-card-group.cjs.js +3 -3
- package/dist/radio-card-group.cjs.js.map +1 -1
- package/dist/radio-card-group.d.ts +5 -0
- package/dist/radio-card-group.d.ts.map +1 -1
- package/dist/radio-card-group.es.js +186 -185
- package/dist/radio-card-group.es.js.map +1 -1
- package/package.json +9 -9
- package/src/radio-card-group.test.tsx +27 -1
- package/src/radio-card-group.tsx +7 -2
|
@@ -79,11 +79,37 @@ describe("RadioButtonGroup", () => {
|
|
|
79
79
|
];
|
|
80
80
|
render(<RadioCardGroup items={items} id="test" data-testid="test" value="1" label="Label" />);
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
const heading = screen.getByRole("heading", { level: 2 });
|
|
83
|
+
expect(heading).toBeInTheDocument();
|
|
84
|
+
expect(heading).toHaveAttribute("id", "test-label");
|
|
85
|
+
expect(heading).toHaveTextContent("Label");
|
|
86
|
+
|
|
83
87
|
expect(screen.getByRole("radiogroup")).toHaveAttribute("aria-labelledby", "test-label");
|
|
84
88
|
expect(screen.getAllByRole("radio")).toHaveLength(2);
|
|
85
89
|
});
|
|
86
90
|
|
|
91
|
+
it("should render with h4 label", () => {
|
|
92
|
+
const items = [
|
|
93
|
+
{ id: "1", title: "1", value: "1" },
|
|
94
|
+
{ id: "2", title: "2", value: "2" },
|
|
95
|
+
];
|
|
96
|
+
render(
|
|
97
|
+
<RadioCardGroup
|
|
98
|
+
items={items}
|
|
99
|
+
id="test"
|
|
100
|
+
data-testid="test"
|
|
101
|
+
value="1"
|
|
102
|
+
label="Label"
|
|
103
|
+
labelTag="h4"
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const heading = screen.getByRole("heading", { level: 4 });
|
|
108
|
+
expect(heading).toBeInTheDocument();
|
|
109
|
+
expect(heading).toHaveAttribute("id", "test-label");
|
|
110
|
+
expect(heading).toHaveTextContent("Label");
|
|
111
|
+
});
|
|
112
|
+
|
|
87
113
|
it("should only render children that are RadioCardItems", () => {
|
|
88
114
|
const items = [
|
|
89
115
|
{ id: "1", title: "1", value: "1" },
|
package/src/radio-card-group.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { Children, cloneElement, ForwardedRef, forwardRef, ReactNode, Ref } from "react";
|
|
2
|
-
import { Heading } from "@purpurds/heading";
|
|
2
|
+
import { type HeadingTagType, Heading } from "@purpurds/heading";
|
|
3
3
|
import * as RadixRadioGroup from "@radix-ui/react-radio-group";
|
|
4
4
|
|
|
5
5
|
import { cx } from "./classnames";
|
|
@@ -40,6 +40,10 @@ export type RadioCardGroupProps = {
|
|
|
40
40
|
* Renders above the radio card group as a heading
|
|
41
41
|
* */
|
|
42
42
|
label?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Changes heading level for label.
|
|
45
|
+
*/
|
|
46
|
+
labelTag?: HeadingTagType;
|
|
43
47
|
/**
|
|
44
48
|
* When true, keyboard navigation will loop from last item to first, and vice versa.
|
|
45
49
|
* */
|
|
@@ -84,6 +88,7 @@ const RadioCardGroupComponent = (
|
|
|
84
88
|
className,
|
|
85
89
|
items,
|
|
86
90
|
label,
|
|
91
|
+
labelTag = "h2",
|
|
87
92
|
loop = true,
|
|
88
93
|
orientation = "vertical",
|
|
89
94
|
radioPosition = "right",
|
|
@@ -99,7 +104,7 @@ const RadioCardGroupComponent = (
|
|
|
99
104
|
<Heading
|
|
100
105
|
data-testid={dataTestId ? `${dataTestId}-label` : undefined}
|
|
101
106
|
id={`${props.id}-label`}
|
|
102
|
-
tag=
|
|
107
|
+
tag={labelTag}
|
|
103
108
|
variant="subsection-100"
|
|
104
109
|
>
|
|
105
110
|
{`${props.required ? "* " : ""}${label}`}
|