Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/components/RadioSimple/RadioSimple.stories.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@ const radioSimpleArgTypes = {
defaultValue: undefined,
},
},
ariaLabel: {
description: 'The ariaLabel is used to provide an aria-label for the RadioSimple.',
control: { type: 'text', required: false },
table: {
type: {
summary: 'string',
},
defaultValue: 'example-ariaLabel',
},
},
ariaLabelledBy: {
description: 'The ariaLabelledBy is used to provide an aria-labelledby for the RadioSimple.',
control: { type: 'text', required: false },
table: {
type: {
summary: 'string',
},
defaultValue: 'example-ariaLabelledBy',
},
},
isDisabled: {
description: 'The isDisabled is to set the disable state for the RadioSimple.',
control: { type: 'boolean', required: false },
Expand Down
1 change: 1 addition & 0 deletions src/components/RadioSimple/RadioSimple.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Example.args = {
padding: '8px',
margin: '8px 8px',
},
'aria-label': 'Some label',
};

export { Example };
17 changes: 2 additions & 15 deletions src/components/RadioSimple/RadioSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,12 @@ import { RadioSimpleGroupContext } from '../RadioSimpleGroup';
* The RadioSimple component.
*/
const RadioSimple: FC<RadioSimpleProps> = (props: RadioSimpleProps) => {
const {
ariaLabel,
ariaLabelledBy,
children,
className,
id,
isDisabled = DEFAULTS.DISABLED,
style,
value,
} = props;
const { children, className, id, isDisabled = DEFAULTS.DISABLED, style, value } = props;
const state = useContext(RadioSimpleGroupContext);
const ref = useRef(null);
const isSelected = state?.selectedValue === value;
const { focusProps, isFocusVisible } = useFocusRing();
const { inputProps } = useRadio(
{ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, ...props },
state,
ref
);
const { inputProps } = useRadio(props, state, ref);

return (
<label
Expand Down
74 changes: 33 additions & 41 deletions src/components/RadioSimple/RadioSimple.types.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
import { CSSProperties, ReactNode } from 'react';
import { AriaLabelRequired } from '../../utils/a11y';
import { AriaRadioProps } from '@react-types/radio';

export interface RadioSimpleProps extends AriaRadioProps {
/**
* Optional ariaLabel on the RadioSimple component.
*/
ariaLabel?: string;

/**
* Optional ariaLabelledBy on the RadioSimple component.
*/
ariaLabelledBy?: string;

/**
* Child components of this RadioSimple.
*/
children?: ReactNode;

/**
* Custom class for overriding this component's CSS.
*/
className?: string;

/**
* The id for the RadioSimple component.
*/
id?: string;

/**
* Disabled state for the RadioSimple component.
*/
isDisabled?: boolean;

/**
* Custom style for overriding this component's CSS.
*/
style?: CSSProperties;

/**
* The value of the RadioSimple component.
*/
value: string;
}
export type RadioSimpleProps = AriaLabelRequired &
AriaRadioProps & {
/**
* Child components of this RadioSimple.
*/
children?: ReactNode;

/**
* Custom class for overriding this component's CSS.
*/
className?: string;

/**
* The id for the RadioSimple component.
*/
id?: string;

/**
* Disabled state for the RadioSimple component.
*/
isDisabled?: boolean;

/**
* Custom style for overriding this component's CSS.
*/
style?: CSSProperties;

/**
* The value of the RadioSimple component.
*/
value: string;
};
14 changes: 14 additions & 0 deletions src/components/RadioSimple/RadioSimple.typetest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Expect, ExpectExtends, ExpectFalse } from '../../utils/typetest.util';
import { RadioSimpleProps } from './RadioSimple.types';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type cases = [
Expect<ExpectExtends<RadioSimpleProps, { 'aria-label': 'Some label'; value: 'A' }>>,
Expect<ExpectExtends<RadioSimpleProps, { 'aria-labelledby': 'some-id'; value: 'A' }>>,

ExpectFalse<ExpectExtends<RadioSimpleProps, { 'aria-label': 'Some label' }>>,
ExpectFalse<ExpectExtends<RadioSimpleProps, { 'aria-labelledby': 'some-id' }>>,
ExpectFalse<ExpectExtends<RadioSimpleProps, { value: 'A' }>>,

ExpectFalse<ExpectExtends<RadioSimpleProps, Record<string, never>>>
];
48 changes: 34 additions & 14 deletions src/components/RadioSimple/RadioSimple.unit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('<RadioSimple />', () => {

const { asFragment } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" />
<RadioSimple aria-label="Some label" children={children} value="red" />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -36,7 +36,7 @@ describe('<RadioSimple />', () => {

const { asFragment } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" ariaLabel={ariaLabel} />
<RadioSimple children={children} value="red" aria-label={ariaLabel} />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -50,7 +50,7 @@ describe('<RadioSimple />', () => {

const { asFragment } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" ariaLabelledBy={ariaLabelledBy} />
<RadioSimple children={children} value="red" aria-labelledby={ariaLabelledBy} />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -64,7 +64,12 @@ describe('<RadioSimple />', () => {

const { asFragment } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" className={className} />
<RadioSimple
aria-label="Some label"
children={children}
value="red"
className={className}
/>
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -78,7 +83,7 @@ describe('<RadioSimple />', () => {

const { asFragment } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" id={id} />
<RadioSimple aria-label="Some label" children={children} value="red" id={id} />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -92,7 +97,12 @@ describe('<RadioSimple />', () => {

const { asFragment } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" isDisabled={isDisabled} />
<RadioSimple
aria-label="Some label"
children={children}
value="red"
isDisabled={isDisabled}
/>
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -106,7 +116,7 @@ describe('<RadioSimple />', () => {

const { asFragment } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" style={style} />
<RadioSimple aria-label="Some label" children={children} value="red" style={style} />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -120,7 +130,7 @@ describe('<RadioSimple />', () => {

const { container } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" />
<RadioSimple aria-label="Some label" children={children} value="red" />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -136,7 +146,7 @@ describe('<RadioSimple />', () => {

const { container } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" ariaLabel={ariaLabel} />
<RadioSimple children={children} value="red" aria-label={ariaLabel} />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -152,7 +162,7 @@ describe('<RadioSimple />', () => {

const { container } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" ariaLabelledBy={ariaLabelledBy} />
<RadioSimple children={children} value="red" aria-labelledby={ariaLabelledBy} />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -168,7 +178,12 @@ describe('<RadioSimple />', () => {

const { container } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" className={className} />
<RadioSimple
aria-label="Some label"
children={children}
value="red"
className={className}
/>
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -184,7 +199,7 @@ describe('<RadioSimple />', () => {

const { container } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" id={id} />
<RadioSimple aria-label="Some label" children={children} value="red" id={id} />
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -200,7 +215,12 @@ describe('<RadioSimple />', () => {

const { container } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" isDisabled={isDisabled} />
<RadioSimple
aria-label="Some label"
children={children}
value="red"
isDisabled={isDisabled}
/>
</RadioSimpleGroupContext.Provider>
);

Expand All @@ -216,7 +236,7 @@ describe('<RadioSimple />', () => {

const { container } = render(
<RadioSimpleGroupContext.Provider value={'red'}>
<RadioSimple children={children} value="red" style={style} />
<RadioSimple aria-label="Some label" children={children} value="red" style={style} />
</RadioSimpleGroupContext.Provider>
);

Expand Down
5 changes: 5 additions & 0 deletions src/components/RadioSimple/RadioSimple.unit.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`<RadioSimple /> snapshot should match snapshot 1`] = `
style="border: 0px; clip-path: inset(50%); height: 1px; margin: 0px -1px -1px 0px; overflow: hidden; padding: 0px; position: absolute; width: 1px; white-space: nowrap;"
>
<input
aria-label="Some label"
tabindex="0"
type="radio"
value="red"
Expand Down Expand Up @@ -98,6 +99,7 @@ exports[`<RadioSimple /> snapshot should match snapshot with className 1`] = `
style="border: 0px; clip-path: inset(50%); height: 1px; margin: 0px -1px -1px 0px; overflow: hidden; padding: 0px; position: absolute; width: 1px; white-space: nowrap;"
>
<input
aria-label="Some label"
tabindex="0"
type="radio"
value="red"
Expand Down Expand Up @@ -127,6 +129,7 @@ exports[`<RadioSimple /> snapshot should match snapshot with id 1`] = `
style="border: 0px; clip-path: inset(50%); height: 1px; margin: 0px -1px -1px 0px; overflow: hidden; padding: 0px; position: absolute; width: 1px; white-space: nowrap;"
>
<input
aria-label="Some label"
id="example-id"
tabindex="0"
type="radio"
Expand Down Expand Up @@ -156,6 +159,7 @@ exports[`<RadioSimple /> snapshot should match snapshot with isDisabled 1`] = `
style="border: 0px; clip-path: inset(50%); height: 1px; margin: 0px -1px -1px 0px; overflow: hidden; padding: 0px; position: absolute; width: 1px; white-space: nowrap;"
>
<input
aria-label="Some label"
disabled=""
type="radio"
value="red"
Expand Down Expand Up @@ -185,6 +189,7 @@ exports[`<RadioSimple /> snapshot should match snapshot with style 1`] = `
style="border: 0px; clip-path: inset(50%); height: 1px; margin: 0px -1px -1px 0px; overflow: hidden; padding: 0px; position: absolute; width: 1px; white-space: nowrap;"
>
<input
aria-label="Some label"
tabindex="0"
type="radio"
value="red"
Expand Down
6 changes: 6 additions & 0 deletions src/components/RadioSimpleGroup/RadioSimpleGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Example.args = {
<RadioSimple
value="red"
key="0"
aria-label="Red"
style={{
display: 'flex',
flexDirection: 'column',
Expand All @@ -48,6 +49,7 @@ Example.args = {
<RadioSimple
value="blue"
key="1"
aria-label="Blue"
style={{
display: 'flex',
flexDirection: 'column',
Expand All @@ -64,6 +66,7 @@ Example.args = {
<RadioSimple
value="yellow"
key="2"
aria-label="Yellow"
style={{
display: 'flex',
flexDirection: 'column',
Expand Down Expand Up @@ -98,6 +101,7 @@ Layout.parameters = {
<RadioSimple
value="grid"
key="0"
aria-label="Grid"
style={{
display: 'flex',
flexDirection: 'column',
Expand All @@ -115,6 +119,7 @@ Layout.parameters = {
<RadioSimple
value="stack"
key="1"
aria-label="Stack"
style={{
display: 'flex',
flexDirection: 'column',
Expand All @@ -132,6 +137,7 @@ Layout.parameters = {
<RadioSimple
value="sideBySide"
key="2"
aria-label="Side by Side"
style={{
display: 'flex',
flexDirection: 'column',
Expand Down
Loading
Loading