Skip to content

Commit

Permalink
Merge pull request #8 from ColeDenslow/accessible-messages
Browse files Browse the repository at this point in the history
feature: Added aria-live props for field messages
  • Loading branch information
CalinR authored Jun 21, 2022
2 parents 8473d7c + 8e2c449 commit 8a1d816
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.14.1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Component library built specifically for storefronts.",
"license": "MIT",
"main": "lib",
"version": "1.3.1",
"version": "1.4.0",
"peerDependencies": {
"classnames": "^2.2.6",
"prop-types": "^15.6.2",
Expand Down
7 changes: 5 additions & 2 deletions src/components/field/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './Field.css';

function Field(props) {
const {
children, className, disabled, helpText, htmlFor, id, label, messageText, messageType, ...otherProps
children, className, disabled, helpText, htmlFor, id, label, messageText, messageType, ariaLive, ...otherProps
} = props;

const classNames = cn([
Expand All @@ -19,7 +19,7 @@ function Field(props) {
]);

const renderMessageText = () => {
return messageText && <div className='stx-field__message'>{ messageText }</div>;
return messageText && <div className='stx-field__message' aria-live={ariaLive}>{ messageText }</div>;
};

const renderHelpText = () => {
Expand Down Expand Up @@ -67,6 +67,9 @@ Field.propTypes = {
/** The type of message to show */
messageType: PropTypes.oneOf(['success', 'warning', 'alert', '']),

/** The aria-live attribute value that will be set on the message if one is given */
ariaLive: PropTypes.oneOf(['polite', 'assertive']),

/** The text to display for the message */
messageText: PropTypes.string,

Expand Down
1 change: 1 addition & 0 deletions src/components/field/Field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Field', () => {
messageText='Some message text'
messageType='alert'
helpText='Some help text'
ariaLive='assertive'
>
<div>
{'There are children'}
Expand Down
2 changes: 2 additions & 0 deletions src/components/field/__snapshots__/Field.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`Field Field render disabled when disabled is true 1`] = `

exports[`Field Field renders with basic props 1`] = `
<Field
ariaLive="assertive"
className="the-class"
data-additional-prop="additional-prop"
helpText="Some help text"
Expand All @@ -22,6 +23,7 @@ exports[`Field Field renders with basic props 1`] = `
There are children
</div>
<div
aria-live="assertive"
className="stx-field__message"
>
Some message text
Expand Down
5 changes: 4 additions & 1 deletion src/components/inputfield/InputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class InputField extends Component {
}

render() {
const { className, disabled, helpText, id, label, messageText, messageType, readOnly, ...otherProps } = this.props;
const { className, disabled, helpText, id, label, messageText, messageType, readOnly, ariaLive, ...otherProps } = this.props;
const classNames = cn([
'stx-field--with-input',
className,
Expand All @@ -31,6 +31,7 @@ class InputField extends Component {
messageText={messageText}
disabled={disabled}
readOnly={readOnly}
ariaLive={ariaLive}
>
<Input
{...otherProps}
Expand Down Expand Up @@ -58,6 +59,8 @@ InputField.propTypes = {
messageType: PropTypes.oneOf(['success', 'warning', 'alert', '']),
/** The text that should appear as a message */
messageText: PropTypes.string,
/** The aria-live attribute value that will be set on the message if one is given */
ariaLive: PropTypes.oneOf(['assertive', 'polite']),
/** Whether or not the field is disabled */
disabled: PropTypes.bool,
/** Whether or not the field is read only */
Expand Down
1 change: 1 addition & 0 deletions src/components/inputfield/InputField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('InputField', () => {
onChange={onChange}
onKeyUp={onKeyUp}
onKeyDown={onKeyDown}
ariaLive='assertive'
selectOnFocus
/>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ exports[`InputField InputField renders with a tabIndex value 1`] = `

exports[`InputField InputField renders with basic props 1`] = `
<Field
ariaLive="assertive"
className="stx-field--with-input html-class"
htmlFor="test-id"
>
Expand Down
7 changes: 6 additions & 1 deletion src/components/selectfield/SelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SelectField extends Component {
}

render() {
const { id, label, className, disabled, readOnly, messageType, messageText, helpText, ...otherProps } = this.props;
const { id, label, className, disabled, readOnly, messageType, messageText, helpText, ariaLive, ...otherProps } = this.props;
const classNames = cn([
'stx-field--with-select',
className,
Expand All @@ -31,6 +31,7 @@ class SelectField extends Component {
messageText={messageText}
disabled={disabled}
readOnly={readOnly}
ariaLive={ariaLive}
>
<Select
{...otherProps}
Expand Down Expand Up @@ -66,6 +67,10 @@ SelectField.propTypes = {

/** The type of message to display */
messageType: PropTypes.oneOf(['alert', 'warning', 'success', '']),

/** The aria-live attribute value that will be set on the message if one is given */
ariaLive: PropTypes.oneOf(['assertive', 'polite']),

/** The order in which fields should gain focus when pressing Tab */
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

Expand Down
1 change: 1 addition & 0 deletions src/components/selectfield/SelectField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('SelectField', () => {
tabIndex='1'
placeholder='Select something'
placeholderValue='placeholder value'
ariaLive='assertive'
>
<option value='one'>One</option>
<option value='two'>Two</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`SelectField SelectField renders with basic props 1`] = `
<SelectField
ariaLive="assertive"
className="the-class"
onBlur={[Function]}
onChange={[Function]}
Expand All @@ -11,6 +12,7 @@ exports[`SelectField SelectField renders with basic props 1`] = `
tabIndex="1"
>
<Field
ariaLive="assertive"
className="stx-field--with-select the-class"
htmlFor="stxField1"
>
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2587,9 +2587,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000989, caniuse-lite@^1.0.30001043:
version "1.0.30001045"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001045.tgz#a770df9de36ad6ca0c34f90eaa797a2dbbb1b619"
integrity sha512-Y8o2Iz1KPcD6FjySbk1sPpvJqchgxk/iow0DABpGyzA1UeQAuxh63Xh0Enj5/BrsYbXtCN32JmR4ZxQTCQ6E6A==
version "1.0.30001357"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001357.tgz"
integrity sha512-b+KbWHdHePp+ZpNj+RDHFChZmuN+J5EvuQUlee9jOQIUAdhv9uvAZeEtUeLAknXbkiu1uxjQ9NLp1ie894CuWg==

capture-exit@^1.2.0:
version "1.2.0"
Expand Down

0 comments on commit 8a1d816

Please sign in to comment.