Skip to content

Commit

Permalink
Accessibility: Improve Welcome guide and modal component. (#19261)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoZehe authored and ellatrix committed Dec 20, 2019
1 parent 14401e0 commit 4108636
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/components/src/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ A custom class to add to the modal.
- Type: `string`
- Required: No

### contentLabel

This property is used as the modal's accessibility label. It is required for accessibility reasons.

- Type: `String`
- Required: Yes

### finishButtonText

Use this to customize the label of the _Finish_ button shown at the end of the guide.
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/guide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import PageControl from './page-control';
import { BackButtonIcon, ForwardButtonIcon } from './icons';
import FinishButton from './finish-button';

export default function Guide( { children, className, finishButtonText, onFinish } ) {
export default function Guide( { children, className, contentLabel, finishButtonText, onFinish } ) {
const [ currentPage, setCurrentPage ] = useState( 0 );

const numberOfPages = Children.count( children );
Expand All @@ -45,6 +45,7 @@ export default function Guide( { children, className, finishButtonText, onFinish
return (
<Modal
className={ classnames( 'components-guide', className ) }
contentLabel={ contentLabel }
onRequestClose={ onFinish }
>

Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/guide/page-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export default function PageControl( { currentPage, numberOfPages, setCurrentPag
return (
<ul className="components-guide__page-control" aria-label={ __( 'Guide controls' ) }>
{ times( numberOfPages, ( page ) => (
<li key={ page }>
<li
key={ page }
aria-current={ page === currentPage }
>
<IconButton
key={ page }
icon={ <PageControlIcon isSelected={ page === currentPage } /> }
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/guide/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ const ModalExample = ( { numberOfPages, ...props } ) => {

export const _default = () => {
const finishButtonText = text( 'finishButtonText', 'Finish' );
const contentLabel = text( 'title', 'Guide title' );
const numberOfPages = number( 'numberOfPages', 3, { range: true, min: 1, max: 10, step: 1 } );

const modalProps = {
finishButtonText,
contentLabel,
numberOfPages,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Modal extends Component {
} }
{ ...otherProps }
>
<div className={ 'components-modal__content' } tabIndex="0">
<div className={ 'components-modal__content' } tabIndex="0" role="document">
<ModalHeader
closeLabel={ closeButtonLabel }
headingId={ headingId }
Expand Down
1 change: 1 addition & 0 deletions packages/edit-post/src/components/welcome-guide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function WelcomeGuide() {
return (
<Guide
className="edit-post-welcome-guide"
contentLabel={ __( 'Welcome to the Block Editor' ) }
finishButtonText={ __( 'Get started' ) }
onFinish={ () => toggleFeature( 'welcomeGuide' ) }
>
Expand Down

0 comments on commit 4108636

Please sign in to comment.