Skip to content

Commit

Permalink
Add aria-describedby attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
takayukister committed Sep 7, 2024
1 parent 6cde8ec commit a4eca13
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 88 deletions.
2 changes: 1 addition & 1 deletion admin/includes/js/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions admin/includes/js/src/config-errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import apiFetch from '@wordpress/api-fetch';

import { iconInCircle } from './utils';
import {
iconInCircle,
canonicalizeName,
} from './utils';


const init = () => {
Expand Down Expand Up @@ -40,6 +43,10 @@ const update = () => {
section,
errors,
} ) );

field.setAttribute( 'aria-describedby',
canonicalizeName( `wpcf7-config-error-for-${ section }` )
);
} else { // Valid field
field.removeAttribute( 'aria-invalid' );
}
Expand All @@ -64,8 +71,12 @@ const createErrorsList = args => {
}

const ul = document.createElement( 'ul' );
ul.setAttribute( 'id', `wpcf7-config-error-for-${ section }` );
ul.setAttribute( 'class', 'config-error' );

ul.setAttribute( 'id',
canonicalizeName( `wpcf7-config-error-for-${ section }` )
);

ul.classList.add( 'config-error' );

errors.forEach( err => {
if ( ! err.message ) {
Expand Down
4 changes: 4 additions & 0 deletions admin/includes/js/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const iconInCircle = icon => {
};


const canonicalizeName = orig => orig.replace( /[^0-9a-z]+/gi, '-' );


export {
iconInCircle,
canonicalizeName,
};
Loading

0 comments on commit a4eca13

Please sign in to comment.