@thecb/components 9.0.2 → 9.0.3-beta.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "9.0.2",
3
+ "version": "9.0.3-beta.10",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
package/src/.DS_Store ADDED
Binary file
Binary file
Binary file
@@ -5,10 +5,9 @@ import { fallbackValues } from "./RadioSection.theme";
5
5
  import { AnimatePresence } from "framer-motion";
6
6
  import RadioButton from "./radio-button/RadioButton";
7
7
  import { Box, Cluster, Stack, Motion } from "../../atoms/layouts";
8
- import { noop } from "../../../util/general";
8
+ import { createIdFromString, noop } from "../../../util/general";
9
9
  import Text from "../../atoms/text";
10
10
  import { CHARADE_GREY } from "../../../constants/colors";
11
- import { createIdFromString } from "../../../util/general";
12
11
  /*
13
12
  Takes an array of section objects, each object should look like:
14
13
  {
@@ -32,6 +31,11 @@ import { createIdFromString } from "../../../util/general";
32
31
 
33
32
  */
34
33
 
34
+ const computeSectionId = section =>
35
+ typeof section.title === "string"
36
+ ? createIdFromString(section.title)
37
+ : section.id;
38
+
35
39
  const RadioSection = ({
36
40
  themeValues,
37
41
  isMobile,
@@ -43,10 +47,11 @@ const RadioSection = ({
43
47
  initiallyOpen = true,
44
48
  openHeight = "auto",
45
49
  containerStyles = "",
46
- ariaDescribedBy
50
+ ariaDescribedBy,
51
+ rightIconsLabel = null
47
52
  }) => {
48
53
  const handleKeyDown = (id, e) => {
49
- if (e?.keyCode === 13) {
54
+ if (e?.keyCode === 13 || e?.keyCode === 32) {
50
55
  toggleOpenSection(id);
51
56
  }
52
57
  };
@@ -101,7 +106,7 @@ const RadioSection = ({
101
106
  borderRadius="4px"
102
107
  extraStyles={containerStyles}
103
108
  >
104
- <Stack childGap="0">
109
+ <Stack childGap="0" role="radiogroup">
105
110
  {sections
106
111
  .filter(section => !section.hidden)
107
112
  .map(section => (
@@ -117,6 +122,8 @@ const RadioSection = ({
117
122
  initial={initiallyOpen ? "open" : "closed"}
118
123
  key={`item-${section.id}`}
119
124
  extraStyles={borderStyles}
125
+ role="radio"
126
+ aria-checked={openSection === section.id}
120
127
  >
121
128
  <Stack childGap="0">
122
129
  <Box
@@ -159,12 +166,12 @@ const RadioSection = ({
159
166
  {!section.hideRadioButton && (
160
167
  <Box padding="0">
161
168
  <RadioButton
162
- name={
163
- typeof section.title === "string"
164
- ? createIdFromString(section.title)
165
- : section.id
166
- }
169
+ id={computeSectionId(section)}
170
+ name={computeSectionId(section)}
167
171
  ariaDescribedBy={ariaDescribedBy}
172
+ ariaLabelledBy={`radio-input-${computeSectionId(
173
+ section
174
+ )}`}
168
175
  radioOn={openSection === section.id}
169
176
  radioFocused={focused === section.id}
170
177
  toggleRadio={
@@ -180,13 +187,22 @@ const RadioSection = ({
180
187
  <Cluster align="center">{section.titleIcon}</Cluster>
181
188
  )}
182
189
  <Box padding={section.titleIcon ? "0 0 0 8px" : "0"}>
183
- <Text variant="p" color={CHARADE_GREY}>
190
+ <Text
191
+ as="label"
192
+ color={CHARADE_GREY}
193
+ htmlFor={`radio-input-${computeSectionId(section)}`}
194
+ >
184
195
  {section.title}
185
196
  </Text>
186
197
  </Box>
187
198
  </Cluster>
188
199
  {section.rightIcons && (
189
- <Cluster childGap="0.5rem">
200
+ <Cluster
201
+ childGap="0.5rem"
202
+ {...(rightIconsLabel !== null
203
+ ? { "aria-label": rightIconsLabel }
204
+ : {})}
205
+ >
190
206
  {section.rightIcons.map(icon => (
191
207
  <RightIcon
192
208
  src={icon.img}
@@ -17,7 +17,9 @@ const RadioButton = ({
17
17
  name,
18
18
  disabled = false,
19
19
  ariaDescribedBy = "",
20
- themeValues
20
+ themeValues,
21
+ ariaLabelledBy = "",
22
+ ariaLabel = null
21
23
  }) => {
22
24
  const buttonBorder = {
23
25
  onFocused: {
@@ -60,6 +62,12 @@ const RadioButton = ({
60
62
  width: "0px"
61
63
  }
62
64
  };
65
+ const extraProps = {};
66
+ if (ariaLabelledBy && ariaLabelledBy.length) {
67
+ extraProps["aria-labelledby"] = ariaLabelledBy;
68
+ } else if (ariaLabel && ariaLabel !== null) {
69
+ extraProps["aria-label"] = ariaLabel;
70
+ }
63
71
 
64
72
  return (
65
73
  <Motion
@@ -77,12 +85,13 @@ const RadioButton = ({
77
85
  }
78
86
  >
79
87
  <HiddenRadioButton
80
- id={`#radio-${name}`}
81
- aria-label={name}
88
+ type="radio"
89
+ id={`radio-${name}`}
82
90
  disabled={disabled}
83
91
  onClick={toggleRadio}
84
92
  aria-describedby={ariaDescribedBy}
85
93
  tabIndex="-1"
94
+ {...extraProps}
86
95
  />
87
96
  <Motion
88
97
  borderWidth="1px"