Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the inserter a11y #527

Merged
merged 4 commits into from
May 3, 2017
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
2 changes: 1 addition & 1 deletion blocks/api/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @var {Array} categories
*/
const categories = [
{ slug: 'common', title: 'Common' }
{ slug: 'common', title: 'Common blocks' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily in scope of this pull request, but the string ought to be translated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way, I guess this should be made translatable? 🙂

];

/**
Expand Down
3 changes: 1 addition & 2 deletions editor/components/icon-button/style.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.editor-icon-button {
display: flex;
align-items: center;
min-width: 36px;
height: 36px;
padding: 8px;
border: none;
background: none;
color: $dark-gray-500;
Expand Down
4 changes: 3 additions & 1 deletion editor/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class Inserter extends wp.element.Component {
icon="insert"
label={ wp.i18n.__( 'Insert block' ) }
onClick={ this.toggle }
className="editor-inserter__toggle" />
className="editor-inserter__toggle"
aria-haspopup="true"
aria-expanded={ opened ? 'true' : 'false' } />
{ opened && <InserterMenu position={ position } onSelect={ this.close } /> }
</div>
);
Expand Down
23 changes: 21 additions & 2 deletions editor/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class InserterMenu extends wp.element.Component {
filterValue: ''
};
this.filter = this.filter.bind( this );
this.instanceId = this.constructor.instances++;
}

filter( event ) {
Expand Down Expand Up @@ -55,10 +56,22 @@ class InserterMenu extends wp.element.Component {
{ categories
.map( ( category ) => !! blocksByCategory[ category.slug ] && (
<div key={ category.slug }>
<div className="editor-inserter__separator">{ category.title }</div>
<div className="editor-inserter__category-blocks">
<div
className="editor-inserter__separator"
id={ `editor-inserter__separator-${ category.slug }-${ this.instanceId }` }
aria-hidden="true"
>
{ category.title }
</div>
<div
className="editor-inserter__category-blocks"
role="menu"
tabIndex="0"
aria-labelledby={ `editor-inserter__separator-${ category.slug }-${ this.instanceId }` }
>
{ blocksByCategory[ category.slug ].map( ( { slug, title, icon } ) => (
<button
role="menuitem"
key={ slug }
className="editor-inserter__block"
onClick={ this.selectBlock( slug ) }
Expand All @@ -72,7 +85,11 @@ class InserterMenu extends wp.element.Component {
) )
}
</div>
<label htmlFor={ `editor-inserter__search-${ this.instanceId }` } className="screen-reader-text">
{ wp.i18n.__( 'Search blocks' ) }
</label>
<input
id={ `editor-inserter__search-${ this.instanceId }` }
type="search"
placeholder={ wp.i18n.__( 'Search…' ) }
className="editor-inserter__search"
Expand All @@ -83,6 +100,8 @@ class InserterMenu extends wp.element.Component {
}
}

InserterMenu.instances = 0;

export default connect(
undefined,
( dispatch ) => ( {
Expand Down
13 changes: 7 additions & 6 deletions editor/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
background: none;
cursor: pointer;
border: none;
width: 36px;
height: 36px;
outline: none;
padding: 0;
transition: color .2s ease;

&:hover {
Expand Down Expand Up @@ -102,7 +99,7 @@
}

.editor-inserter__content {
max-height: 180px;
max-height: 186px;
overflow: auto;

&:focus {
Expand Down Expand Up @@ -136,15 +133,18 @@ input[type=search].editor-inserter__search {
width: 50%;
font-size: 12px;
color: $dark-gray-500;
margin: 0;
padding: 8px;
align-items: center;
cursor: pointer;
border: 1px solid transparent;
background: none;
line-height: 20px;

&:hover {
&:hover,
&:focus {
border: 1px solid $dark-gray-500;
position: relative;
outline: none;
}

&:active,
Expand All @@ -161,6 +161,7 @@ input[type=search].editor-inserter__search {

.editor-inserter__separator {
display: block;
margin: 0;
padding: 4px 8px;
font-size: 11px;
font-weight: 600;
Expand Down
8 changes: 4 additions & 4 deletions editor/components/toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

.editor-toolbar__control.editor-button {
display: inline-flex;
align-items: flex-end;
margin: 3px;
margin-left: 0;
padding: 6px;
background: none;
border: 1px solid transparent;
outline: none;
Expand Down Expand Up @@ -39,9 +39,9 @@
font-family: $default-font;
font-size: 10px;
font-weight: bold;
position: absolute;
bottom: 8px;
right: 5px;
position: relative;
top: -1px;
margin-left: -3px;
}
}

Expand Down