From 2b50adcdbfb6f1489c5f72935a274f14b9970bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Mon, 2 Mar 2020 14:35:34 +0100 Subject: [PATCH 01/17] First stab at using VisuallyHidden component --- .../src/components/block-navigation/list.js | 6 ++--- .../components/button-block-appender/index.js | 6 ++--- .../src/components/inserter/menu.js | 12 ++++++--- .../link-control/settings-drawer.js | 6 ++--- .../test/__snapshots__/index.js.snap | 2 +- .../responsive-block-control/label.js | 8 +++--- .../responsive-block-control/style.scss | 23 ++++++++--------- packages/block-library/src/archives/index.php | 2 +- packages/block-library/src/categories/edit.js | 5 ++-- packages/block-library/src/gallery/gallery.js | 12 +++++---- packages/block-library/src/search/index.php | 2 +- .../custom-gradient-picker/control-points.js | 5 ++-- .../src/custom-select-control/index.js | 25 ++++++++++++++++--- 13 files changed, 67 insertions(+), 47 deletions(-) diff --git a/packages/block-editor/src/components/block-navigation/list.js b/packages/block-editor/src/components/block-navigation/list.js index 32c8eba5049e89..55a1b28848b9dd 100644 --- a/packages/block-editor/src/components/block-navigation/list.js +++ b/packages/block-editor/src/components/block-navigation/list.js @@ -7,7 +7,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { Button } from '@wordpress/components'; +import { Button, VisuallyHidden } from '@wordpress/components'; import { __experimentalGetBlockLabel as getBlockLabel, getBlockType, @@ -58,9 +58,9 @@ export default function BlockNavigationList( { { getBlockLabel( blockType, block.attributes ) } { isSelected && ( - + { __( '(selected block)' ) } - + ) } diff --git a/packages/block-editor/src/components/button-block-appender/index.js b/packages/block-editor/src/components/button-block-appender/index.js index 371ef144e7a160..91de376e909117 100644 --- a/packages/block-editor/src/components/button-block-appender/index.js +++ b/packages/block-editor/src/components/button-block-appender/index.js @@ -6,7 +6,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { Button, Tooltip } from '@wordpress/components'; +import { Button, Tooltip, VisuallyHidden } from '@wordpress/components'; import { _x, sprintf } from '@wordpress/i18n'; import { Icon, plus } from '@wordpress/icons'; @@ -62,9 +62,7 @@ function ButtonBlockAppender( { disabled={ disabled } label={ label } > - - { label } - + { label } diff --git a/packages/block-editor/src/components/inserter/menu.js b/packages/block-editor/src/components/inserter/menu.js index 1cff0dd71c0737..69b23a6eba1ce1 100644 --- a/packages/block-editor/src/components/inserter/menu.js +++ b/packages/block-editor/src/components/inserter/menu.js @@ -20,7 +20,11 @@ import scrollIntoView from 'dom-scroll-into-view'; import { speak } from '@wordpress/a11y'; import { __, _n, _x, sprintf } from '@wordpress/i18n'; import { Component, createRef } from '@wordpress/element'; -import { PanelBody, withSpokenMessages } from '@wordpress/components'; +import { + PanelBody, + withSpokenMessages, + VisuallyHidden, +} from '@wordpress/components'; import { isReusableBlock, createBlock, @@ -316,12 +320,12 @@ export class InserterMenu extends Component { onKeyDown={ this.onKeyDown } >
- + - + { __( 'Currently selected link settings' ) } - + { theSettings } ); diff --git a/packages/block-editor/src/components/link-control/test/__snapshots__/index.js.snap b/packages/block-editor/src/components/link-control/test/__snapshots__/index.js.snap index faa5202cd23a8a..857f93071f8b04 100644 --- a/packages/block-editor/src/components/link-control/test/__snapshots__/index.js.snap +++ b/packages/block-editor/src/components/link-control/test/__snapshots__/index.js.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Basic rendering should render 1`] = `""`; +exports[`Basic rendering should render 1`] = `""`; diff --git a/packages/block-editor/src/components/responsive-block-control/label.js b/packages/block-editor/src/components/responsive-block-control/label.js index dba8fe9e310c74..f1445c0872df70 100644 --- a/packages/block-editor/src/components/responsive-block-control/label.js +++ b/packages/block-editor/src/components/responsive-block-control/label.js @@ -2,6 +2,7 @@ * WordPress dependencies */ import { useInstanceId } from '@wordpress/compose'; +import { VisuallyHidden } from '@wordpress/components'; import { _x, sprintf } from '@wordpress/i18n'; import { Fragment } from '@wordpress/element'; @@ -26,12 +27,9 @@ export default function ResponsiveBlockControlLabel( { { viewport.label } - + { accessibleLabel } - + ); } diff --git a/packages/block-editor/src/components/responsive-block-control/style.scss b/packages/block-editor/src/components/responsive-block-control/style.scss index bb1ffd6683accc..336893364e1230 100644 --- a/packages/block-editor/src/components/responsive-block-control/style.scss +++ b/packages/block-editor/src/components/responsive-block-control/style.scss @@ -1,15 +1,3 @@ -@mixin screen-reader-text() { - border: 0; - clip: rect(1px, 1px, 1px, 1px); - clip-path: inset(50%); - height: 1px; - margin: -1px; - overflow: hidden; - padding: 0; - position: absolute; - width: 1px; - word-wrap: normal !important; -} .block-editor-responsive-block-control { margin-bottom: $block-padding*2; @@ -43,5 +31,14 @@ } .block-editor-responsive-block-control .components-base-control__help { - @include screen-reader-text(); + border: 0; + clip: rect(1px, 1px, 1px, 1px); + clip-path: inset(50%); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; + word-wrap: normal !important; } diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index 172b1c7c8407ed..ca655f8cfb3950 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -68,7 +68,7 @@ function render_block_core_archives( $attributes ) { $label = esc_attr( $label ); - $block_content = ' + $block_content = ' '; diff --git a/packages/block-library/src/categories/edit.js b/packages/block-library/src/categories/edit.js index 7fb05234a6743f..b17f3007b4329d 100644 --- a/packages/block-library/src/categories/edit.js +++ b/packages/block-library/src/categories/edit.js @@ -11,6 +11,7 @@ import { Placeholder, Spinner, ToggleControl, + VisuallyHidden, } from '@wordpress/components'; import { compose, withInstanceId } from '@wordpress/compose'; import { withSelect } from '@wordpress/data'; @@ -136,9 +137,9 @@ class CategoriesEdit extends Component { const selectId = `blocks-category-select-${ instanceId }`; return ( <> - +
"`; +exports[`Basic rendering should render 1`] = `""`; diff --git a/packages/block-editor/src/components/responsive-block-control/label.js b/packages/block-editor/src/components/responsive-block-control/label.js index f1445c0872df70..84a92bb337b92c 100644 --- a/packages/block-editor/src/components/responsive-block-control/label.js +++ b/packages/block-editor/src/components/responsive-block-control/label.js @@ -27,7 +27,7 @@ export default function ResponsiveBlockControlLabel( { { viewport.label } - + { accessibleLabel } diff --git a/packages/block-editor/src/components/responsive-block-control/test/__snapshots__/index.js.snap b/packages/block-editor/src/components/responsive-block-control/test/__snapshots__/index.js.snap index 50527efe610212..fc1b0a65e95a14 100644 --- a/packages/block-editor/src/components/responsive-block-control/test/__snapshots__/index.js.snap +++ b/packages/block-editor/src/components/responsive-block-control/test/__snapshots__/index.js.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Basic rendering should render with required props 1`] = `"
Padding

Toggle between using the same value for all screen sizes or using a unique value per screen size.

All is used here for testing purposes to ensure we have access to details about the device.

"`; +exports[`Basic rendering should render with required props 1`] = `"
Padding

Toggle between using the same value for all screen sizes or using a unique value per screen size.

All is used here for testing purposes to ensure we have access to details about the device.

"`; diff --git a/packages/block-library/src/categories/edit.js b/packages/block-library/src/categories/edit.js index b17f3007b4329d..ef63da087e75b1 100644 --- a/packages/block-library/src/categories/edit.js +++ b/packages/block-library/src/categories/edit.js @@ -137,8 +137,8 @@ class CategoriesEdit extends Component { const selectId = `blocks-category-select-${ instanceId }`; return ( <> - - { __( 'Categories' ) } + + - - { __( 'Color value in HSL' ) } + + { __( 'Color value in HSL' ) }
- + { __( 'Use your left or right arrow keys or drag and drop with the mouse to change the gradient position. Press the button to change the color or remove the control point.' ) } diff --git a/packages/components/src/custom-select-control/index.js b/packages/components/src/custom-select-control/index.js index 7cea0a4970e7df..c4b1badb2b983b 100644 --- a/packages/components/src/custom-select-control/index.js +++ b/packages/components/src/custom-select-control/index.js @@ -92,8 +92,17 @@ export default function CustomSelectControl( { delete menuProps[ 'aria-activedescendant' ]; } - const LabelComponent = hideLabelFromVision ? VisuallyHidden : 'label'; - const labelProps = hideLabelFromVision ? { as: 'label' } : {}; + const labelElem = ( + /* eslint-disable-next-line jsx-a11y/label-has-associated-control, jsx-a11y/label-has-for */ + + ); + return (
- { /* eslint-disable-next-line jsx-a11y/label-has-associated-control, jsx-a11y/label-has-for */ } - - { label } - - - - { label } - + { hideLabelFromVision ? ( + { labelElem } + ) : ( + labelElem + ) }
Warning
diff --git a/packages/editor/src/components/post-preview-button/index.js b/packages/editor/src/components/post-preview-button/index.js index 9226451b3aef32..f7b29f15758813 100644 --- a/packages/editor/src/components/post-preview-button/index.js +++ b/packages/editor/src/components/post-preview-button/index.js @@ -8,7 +8,7 @@ import classnames from 'classnames'; * WordPress dependencies */ import { Component, createRef, renderToString } from '@wordpress/element'; -import { Button, Path, SVG } from '@wordpress/components'; +import { Button, Path, SVG, VisuallyHidden } from '@wordpress/components'; import { __, _x } from '@wordpress/i18n'; import { withSelect, withDispatch } from '@wordpress/data'; import { ifCondition, compose } from '@wordpress/compose'; @@ -207,10 +207,10 @@ export class PostPreviewButton extends Component { { this.props.textContent ? this.props.textContent : _x( 'Preview', 'imperative verb' ) } - + { /* translators: accessibility text */ __( '(opens in a new tab)' ) } - +
); } diff --git a/packages/editor/src/components/post-preview-button/test/__snapshots__/index.js.snap b/packages/editor/src/components/post-preview-button/test/__snapshots__/index.js.snap index 43be77565caa5e..3e211f0adc4661 100644 --- a/packages/editor/src/components/post-preview-button/test/__snapshots__/index.js.snap +++ b/packages/editor/src/components/post-preview-button/test/__snapshots__/index.js.snap @@ -10,11 +10,9 @@ exports[`PostPreviewButton render() should render currentPostLink otherwise 1`] target="wp-preview-1" > Preview - + (opens in a new tab) - +
`; @@ -28,10 +26,8 @@ exports[`PostPreviewButton render() should render previewLink if provided 1`] = target="wp-preview-1" > Preview - + (opens in a new tab) - + `; diff --git a/packages/editor/src/components/post-text-editor/index.js b/packages/editor/src/components/post-text-editor/index.js index dcfd611ea60115..193cc268b70839 100644 --- a/packages/editor/src/components/post-text-editor/index.js +++ b/packages/editor/src/components/post-text-editor/index.js @@ -11,6 +11,7 @@ import { Component } from '@wordpress/element'; import { parse } from '@wordpress/blocks'; import { withSelect, withDispatch } from '@wordpress/data'; import { withInstanceId, compose } from '@wordpress/compose'; +import { VisuallyHidden } from '@wordpress/components'; export class PostTextEditor extends Component { constructor() { @@ -67,12 +68,11 @@ export class PostTextEditor extends Component { const { instanceId } = this.props; return ( <> - + + +