Skip to content

Commit

Permalink
aria-labelledby and aria-label
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxFrank13 committed Jul 24, 2023
1 parent d4a2e15 commit b8f18ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 71 deletions.
9 changes: 9 additions & 0 deletions src/SelectableBox/SelectableBoxSet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { getInputType } from './utils';
import { requiredWhenNot } from '../utils/propTypes';

const INPUT_TYPES = [
'radio',
Expand Down Expand Up @@ -64,6 +65,12 @@ SelectableBoxSet.propTypes = {
columns: PropTypes.number,
/** A class that is be appended to the base element. */
className: PropTypes.string,
/** An accessible label must be provided to the SelectableBoxSet.
*
* This can be done with `ariaLabelledby` */
ariaLabelledby: PropTypes.string,
/** If not using ariaLabelledby, an ariaLabel must be provided */
ariaLabel: requiredWhenNot(PropTypes.string, 'ariaLabelledby'),
};

SelectableBoxSet.defaultProps = {
Expand All @@ -74,6 +81,8 @@ SelectableBoxSet.defaultProps = {
type: 'radio',
columns: DEFAULT_COLUMNS_NUMBER,
className: undefined,
ariaLabelledby: undefined,
ariaLabel: undefined,
};

export default SelectableBoxSet;
3 changes: 1 addition & 2 deletions src/SelectableBox/tests/SelectableBoxSet.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ describe('<SelectableBox.Set />', () => {
expect(tree).toMatchSnapshot();
});
it('renders with props', () => {
const tree = renderer.create((<SelectableRadioSet name="testName" aria-label="test-label" />)).toJSON();
expect(tree).toMatchSnapshot();
// TODO: use react-testing-library to make assertion
});
it('correct render when type prop is changed', () => {
const setWrapper = mount(<SelectableRadioSet name="set" />);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<SelectableBox.Set /> correct rendering renders with props 1`] = `
<div
aria-label="test-label"
className="pgn__selectable_box-set pgn__selectable_box-set--2 pgn__form-control-set"
role="radiogroup"
>
<div
className="pgn__selectable_box"
onClick={[Function]}
onFocus={[Function]}
onKeyPress={[Function]}
role="button"
tabIndex={0}
>
<input
className="pgn__form-radio-input"
defaultChecked={false}
hidden={true}
name="testName"
onChange={[Function]}
tabIndex={-1}
type="radio"
value={1}
/>
SelectableRadio1
</div>
<div
className="pgn__selectable_box"
onClick={[Function]}
onFocus={[Function]}
onKeyPress={[Function]}
role="button"
tabIndex={0}
>
<input
className="pgn__form-radio-input"
defaultChecked={false}
hidden={true}
name="testName"
onChange={[Function]}
tabIndex={-1}
type="radio"
value={2}
/>
SelectableRadio2
</div>
<div
className="pgn__selectable_box"
onClick={[Function]}
onFocus={[Function]}
onKeyPress={[Function]}
role="button"
tabIndex={0}
>
<input
className="pgn__form-radio-input"
defaultChecked={false}
hidden={true}
name="testName"
onChange={[Function]}
tabIndex={-1}
type="radio"
value={3}
/>
SelectableRadio3
</div>
</div>
`;

exports[`<SelectableBox.Set /> correct rendering renders without props 1`] = `
<div
className="pgn__selectable_box-set pgn__selectable_box-set--2 pgn__form-control-set"
Expand Down

0 comments on commit b8f18ea

Please sign in to comment.