Skip to content

Commit 455c491

Browse files
authored
fix(choice-group): segmented item borders and focus behaviour #101 (#513)
1 parent 24be799 commit 455c491

3 files changed

Lines changed: 74 additions & 23 deletions

File tree

src/tedi/components/form/choice-group/choice-group.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const ChoiceGroup = (props: ChoiceGroupProps): React.ReactElement => {
6767
indeterminateCheck,
6868
indeterminateCheckProps = {},
6969
color,
70-
layout,
70+
layout = 'separated',
7171
showIndicator,
7272
...rest
7373
} = getCurrentBreakpointProps(props);
@@ -188,8 +188,8 @@ export const ChoiceGroup = (props: ChoiceGroupProps): React.ReactElement => {
188188
)}
189189
<Row
190190
direction={direction}
191-
gutterX={direction === 'row' && layout === 'segmented' ? 0 : 2}
192-
gutterY={direction === 'row' && layout === 'segmented' ? 0 : 1}
191+
gutterX={layout === 'segmented' ? 0 : 2}
192+
gutterY={layout === 'segmented' ? 0 : 1}
193193
gap={
194194
variant === 'default'
195195
? isBreakpointBelow(currentBreakpoint, 'md')

src/tedi/components/form/choice-group/components/choice-group-item/choice-group-item.module.scss

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
cursor: unset;
2222
}
2323

24-
.tedi-choice-group-item__input {
25-
@include mixins.visually-hidden;
26-
}
27-
2824
&__label {
2925
box-sizing: border-box;
3026
display: block;
@@ -51,7 +47,7 @@
5147
}
5248
}
5349

54-
&:has(:focus-visible) {
50+
&:focus-visible {
5551
z-index: 5;
5652
outline: 2px solid var(--form-checkbox-radio-default-border-selected);
5753
outline-offset: 2px;
@@ -63,10 +59,6 @@
6359
background-color: var(--form-checkbox-radio-card-primary-default-background);
6460
border: 1px solid var(--form-checkbox-radio-card-primary-default-border-group);
6561

66-
&.tedi-choice-group-item--checkbox {
67-
border-color: var(--filter-primary-inactive-background);
68-
}
69-
7062
&.tedi-choice-group-item--checked {
7163
background-color: var(--form-checkbox-radio-card-primary-selected-background);
7264
border-color: var(--form-checkbox-radio-card-primary-hover-border);
@@ -142,12 +134,6 @@
142134
}
143135
}
144136

145-
&:has(:focus-visible) {
146-
z-index: 5;
147-
outline: 2px solid var(--form-checkbox-radio-default-border-selected);
148-
outline-offset: 2px;
149-
}
150-
151137
&.tedi-choice-group-item--disabled {
152138
color: var(--form-checkbox-radio-card-primary-disabled-default-text);
153139
background-color: var(--form-checkbox-radio-card-secondary-disabled-default-background);
@@ -164,19 +150,44 @@
164150
margin-top: -1px;
165151
}
166152

153+
&:first-of-type .tedi-choice-group-item {
154+
border-top-left-radius: var(--border-radius-default);
155+
border-top-right-radius: var(--border-radius-default);
156+
}
157+
158+
&:last-of-type .tedi-choice-group-item {
159+
border-bottom-right-radius: var(--border-radius-default);
160+
border-bottom-left-radius: var(--border-radius-default);
161+
}
162+
167163
&:not(:first-of-type) .tedi-choice-group-item--disabled {
168164
margin-top: 1px;
169165
border-top-color: var(--form-checkbox-radio-card-secondary-disabled-default-border);
170166
}
167+
}
168+
169+
&.tedi-choice-group-item--column-reverse {
170+
&:not(:first-of-type, :disabled) {
171+
margin-bottom: -1px;
172+
}
173+
174+
&:last-of-type:disabled {
175+
margin-bottom: 0;
176+
}
171177

172178
&:first-of-type .tedi-choice-group-item {
179+
border-bottom-right-radius: var(--border-radius-default);
180+
border-bottom-left-radius: var(--border-radius-default);
181+
}
182+
183+
&:last-of-type .tedi-choice-group-item {
173184
border-top-left-radius: var(--border-radius-default);
174185
border-top-right-radius: var(--border-radius-default);
175186
}
176187

177-
&:last-of-type .tedi-choice-group-item {
178-
border-bottom-right-radius: var(--border-radius-default);
179-
border-bottom-left-radius: var(--border-radius-default);
188+
&:not(:first-of-type) .tedi-choice-group-item--disabled {
189+
margin-bottom: 1px;
190+
border-bottom-color: var(--form-checkbox-radio-card-secondary-disabled-default-border);
180191
}
181192
}
182193

@@ -213,6 +224,39 @@
213224
}
214225
}
215226

227+
&.tedi-choice-group-item--row-reverse {
228+
&:not(:first-of-type) .tedi-choice-group-item {
229+
margin-right: -1px;
230+
}
231+
232+
&:not(:first-of-type) .tedi-choice-group-item--disabled {
233+
margin-right: 0;
234+
235+
&.tedi-choice-group-item--card-primary {
236+
border-right-color: var(--form-checkbox-radio-card-secondary-disabled-default-border);
237+
}
238+
239+
&.tedi-choice-group-item--card-secondary {
240+
border-right-color: var(--form-checkbox-radio-card-secondary-default-background);
241+
}
242+
}
243+
244+
&:first-of-type .tedi-choice-group-item {
245+
border-top-right-radius: var(--border-radius-default);
246+
border-bottom-right-radius: var(--border-radius-default);
247+
}
248+
249+
&:last-of-type .tedi-choice-group-item {
250+
border-top-left-radius: var(--border-radius-default);
251+
border-bottom-left-radius: var(--border-radius-default);
252+
}
253+
254+
.tedi-choice-group-item--disabled.tedi-choice-group-item--card-secondary {
255+
color: var(--form-checkbox-radio-card-primary-disabled-default-text);
256+
background-color: var(--form-checkbox-radio-card-secondary-disabled-default-background);
257+
}
258+
}
259+
216260
.tedi-choice-group-item--card-primary:not(.tedi-choice-group-item--disabled):hover {
217261
background-color: var(--form-checkbox-radio-card-primary-hover-background);
218262
border-color: var(--form-checkbox-radio-card-primary-hover-border);

src/tedi/components/form/choice-group/components/choice-group-item/choice-group-item.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ export const ChoiceGroupItem = (props: ExtendedChoiceGroupItemProps): React.Reac
9393
};
9494
return (
9595
<Col {...colProps} className={ColumnBEM}>
96-
<div className={ChoiceGroupItemBEM} onClick={handleClick} role={type} aria-checked={isChecked}>
96+
<div
97+
className={ChoiceGroupItemBEM}
98+
tabIndex={disabled ? -1 : 0}
99+
onClick={handleClick}
100+
role={type}
101+
aria-checked={isChecked}
102+
>
97103
{variant === 'default' || showIndicator ? (
98104
<InputComponent
99105
id={id}
@@ -128,9 +134,10 @@ export const ChoiceGroupItem = (props: ExtendedChoiceGroupItemProps): React.Reac
128134
onChange={(e) => {
129135
onChangeHandler(value, e.target.checked);
130136
}}
131-
className={styles['tedi-choice-group-item__input']}
137+
className="visually-hidden"
132138
role={type === 'radio' ? 'radio' : undefined}
133139
aria-checked={isChecked}
140+
tabIndex={-1}
134141
/>
135142
<label htmlFor={id} className={styles['tedi-choice-group-item__label']}>
136143
{label}

0 commit comments

Comments
 (0)