Skip to content

Commit 4629fc3

Browse files
author
Kubit
committed
Add new aria-labels to RadioButton group component
1 parent e1deaa6 commit 4629fc3

File tree

6 files changed

+322
-37
lines changed

6 files changed

+322
-37
lines changed

src/components/radioButtonGroup/components/radioButton/radioButton.styled.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
import styled, { css } from 'styled-components';
22

33
import { focusVisibleAlt } from '@/styles/mixins';
4-
import { VariantStyles } from '@/types';
54
import { getStyles } from '@/utils';
65

7-
import {
8-
IRadioButtonStyled,
9-
RadioButtonBaseStyles,
10-
RadioButtonStateType,
11-
RadioButtonStylesType,
12-
} from './types';
13-
14-
interface IRadioButtonContentStyled {
15-
styles: VariantStyles<RadioButtonStylesType>;
16-
state: RadioButtonStateType;
17-
hasLabel?: boolean;
18-
lastChild?: boolean;
19-
}
20-
21-
interface IRadioButtonErrorStyled {
22-
styles?: RadioButtonBaseStyles;
23-
}
6+
import { RadioButtonBaseStyles, RadioButtonStateStylesType, RadioButtonStateType } from './types';
247

258
interface IRadioButtonErrorStyled {
269
styles?: RadioButtonBaseStyles;
@@ -39,11 +22,14 @@ const getDynamicStyles = (styles?: RadioButtonBaseStyles) => css`
3922
}
4023
`;
4124

42-
export const RadioButtonContainerInput = styled.div<IRadioButtonStyled>`
25+
export const RadioButtonContainerInput = styled.div<{ styles: RadioButtonStateStylesType }>`
4326
${props => getStyles(props.styles[RadioButtonStateType.DEFAULT]?.radioButtonContainer)}
4427
`;
4528

46-
export const RadioButtonInputStyled = styled.input<IRadioButtonStyled>`
29+
export const RadioButtonInputStyled = styled.input<{
30+
styles: RadioButtonStateStylesType & { altVariant?: boolean };
31+
state?: RadioButtonStateType;
32+
}>`
4733
appearance: none;
4834
cursor: pointer;
4935
display: inline-block;
@@ -59,7 +45,12 @@ export const RadioButtonInputStyled = styled.input<IRadioButtonStyled>`
5945
${({ styles }) => styles.altVariant && focusVisibleAlt()}
6046
`;
6147

62-
export const RadioButtonStyled = styled.div<IRadioButtonContentStyled>`
48+
export const RadioButtonStyled = styled.div<{
49+
styles: RadioButtonStateStylesType;
50+
state: RadioButtonStateType;
51+
hasLabel?: boolean;
52+
lastChild?: boolean;
53+
}>`
6354
display: ${props => (props.hasLabel ? 'grid' : 'block')};
6455
grid-template-columns: auto 1fr;
6556
${props => getStyles(props.styles?.[props.state]?.rowContainer)}
@@ -76,13 +67,13 @@ export const RadioButtonLabelStyled = styled.div`
7667
align-items: center;
7768
`;
7869

79-
export const RadioButtonErrorStyled = styled.div<IRadioButtonErrorStyled>`
70+
export const RadioButtonErrorStyled = styled.div<{ styles?: RadioButtonBaseStyles }>`
8071
${({ styles }) => getStyles(styles?.errorMessageContainer)};
8172
p {
8273
display: flex;
8374
}
8475
`;
8576

86-
export const ErrorIconWrapperStyled = styled.span<IRadioButtonErrorStyled>`
77+
export const ErrorIconWrapperStyled = styled.span<{ styles?: RadioButtonBaseStyles }>`
8778
${({ styles }) => getStyles(styles?.errorMessageIconContainer)};
8879
`;

src/components/radioButtonGroup/components/radioButton/radioButtonStandAlone.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ export const RadioButtonStandAlone = (props: IRadioButtonStandAlone): JSX.Elemen
5050
error: props.error,
5151
})
5252
}
53+
aria-hidden={props['aria-hidden']}
54+
aria-label={props['aria-label']}
55+
aria-labelledby={props['aria-labelledby']}
5356
checked={props.checked}
5457
data-testid={`${props.dataTestId}Input`}
5558
disabled={props.disabled}
5659
id={inputId}
5760
name={props.name}
5861
state={props.state}
5962
styles={props.styles}
63+
tabIndex={props.tabIndex}
6064
type="radio"
6165
value={props.value}
6266
onBlur={props.onBlur}

src/components/radioButtonGroup/components/radioButton/types/radioButton.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ import { VariantStyles } from '@/types/variantStyles';
99
import { RadioButtonStylesType } from './radioButtonTheme';
1010
import { RadioButtonStateType } from './state';
1111

12-
export interface IRadioButtonStyled {
13-
styles: VariantStyles<RadioButtonStylesType> & { altVariant?: boolean };
14-
state?: RadioButtonStateType;
15-
hasLabel?: boolean;
16-
}
17-
1812
export type RadioButtonLabelType = Omit<ILabelStandAlone, 'children' | 'inputId'> & {
1913
content?: string;
2014
};
@@ -23,9 +17,15 @@ export type RadioButtonSubtitleType = Omit<IText<string>, 'children'> & {
2317
content?: JSX.Element | string;
2418
};
2519

26-
export interface IRadioButtonStandAlone extends IRadioButtonStyled {
27-
checked: boolean;
28-
name: string;
20+
type RadioButtonAriaAttributes = Pick<
21+
React.AriaAttributes,
22+
'aria-label' | 'aria-labelledby' | 'aria-hidden'
23+
>;
24+
25+
export interface IRadioButtonStandAlone extends RadioButtonAriaAttributes {
26+
styles: VariantStyles<RadioButtonStylesType> & { altVariant?: boolean };
27+
checked?: boolean;
28+
name?: string;
2929
label?: RadioButtonLabelType;
3030
errorMessage?: string;
3131
errorIcon?: IElementOrIcon;
@@ -36,10 +36,11 @@ export interface IRadioButtonStandAlone extends IRadioButtonStyled {
3636
state: RadioButtonStateType;
3737
error?: boolean;
3838
disabled?: boolean;
39-
value: string | number;
39+
value?: string | number;
4040
dataTestId?: string;
4141
screenReaderId?: string;
4242
id?: string;
43+
tabIndex?: number;
4344
lastChild?: boolean;
4445
}
4546
/**
@@ -50,10 +51,11 @@ export interface IRadioButtonStandAlone extends IRadioButtonStyled {
5051
* @property {V} variant - Variant of the radio button.
5152
*/
5253
export interface IRadioButton<V = undefined extends string ? unknown : string>
53-
extends Omit<IRadioButtonStandAlone, 'state'> {
54+
extends Omit<IRadioButtonStandAlone, 'state' | 'styles'> {
5455
/**
5556
* @deprecated `state` is deprecated. Please use `error`, `disabled` or `checked` instead.
5657
*/
5758
state?: RadioButtonStateType;
59+
styles?: VariantStyles<RadioButtonStylesType> & { altVariant?: boolean };
5860
variant: V;
5961
}

src/components/radioButtonGroup/components/radioButton/types/radioButtonTheme.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ export type RadioButtonBaseStyles = {
2424
};
2525
};
2626

27+
export type RadioButtonStateStylesType = {
28+
[state in RadioButtonStateType]?: RadioButtonBaseStyles;
29+
};
30+
2731
export type RadioButtonStylesType<P extends string = string> = {
28-
[variant in P]: {
29-
[state in RadioButtonStateType]?: RadioButtonBaseStyles;
30-
};
32+
[variant in P]: RadioButtonStateStylesType;
3133
};

0 commit comments

Comments
 (0)