Skip to content

Commit c901d74

Browse files
authored
Fix (accessibility): accessibility of blocks (#3593)
* fix accessibility - carousel - horizontal scroller - notification - posts - progress bar - progress circle * update version * fix save and deprecated * remove props * fix props * updated save.js * fix block validation error for progress circle * pass props
1 parent ecd7995 commit c901d74

File tree

12 files changed

+138
-7
lines changed

12 files changed

+138
-7
lines changed

src/block/carousel/deprecated.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ import { Save } from './save'
77
import { attributes } from './schema'
88

99
import { withVersion } from '~stackable/higher-order'
10+
import { addFilter } from '@wordpress/hooks'
11+
import { semverCompare } from '~stackable/util'
12+
13+
addFilter( 'stackable.carousel.save.slider-props', 'stackable/3.19.0', ( sliderProps, props ) => {
14+
if ( semverCompare( props.version, '<', '3.19.0' ) ) {
15+
return {
16+
...sliderProps,
17+
tabIndex: undefined,
18+
}
19+
}
20+
21+
return sliderProps
22+
} )
1023

1124
const deprecated = [
1225
{

src/block/carousel/save.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export const Save = props => {
8181
role="list"
8282
data-autoplay={ attributes.autoplay ? ( attributes.autoplaySpeed || '4000' ) : undefined }
8383
data-label-slide-of={ attributes.ariaLabelPrev || 'Slide %%d of %%d' }
84+
tabIndex={ 0 }
85+
{ ...applyFilters( 'stackable.carousel.save.slider-props', {}, props ) }
8486
>
8587
<InnerBlocks.Content />
8688
</div>

src/block/horizontal-scroller/deprecated.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import {
88
} from '~stackable/block-components'
99
import { addFilter } from '@wordpress/hooks'
1010
import compareVersions from 'compare-versions'
11+
import { semverCompare } from '~stackable/util'
12+
13+
addFilter( 'stackable.horizontal-scroller.save.scroller-props', 'stackable/3.19.0', ( scrollerProps, props ) => {
14+
if ( semverCompare( props.version, '<', '3.19.0' ) ) {
15+
return {
16+
...scrollerProps,
17+
tabIndex: undefined,
18+
}
19+
}
20+
21+
return scrollerProps
22+
} )
1123

1224
// Previously, our horizontal scroller always had the stk--fit-content class (which was wrong).
1325
addFilter( 'stackable.horizontal-scroller.save.contentClassNames', 'stackable/3_8_0', ( classes, props ) => {

src/block/horizontal-scroller/save.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export const Save = props => {
5454
>
5555
{ attributes.generatedCss && <style>{ attributes.generatedCss }</style> }
5656
<CustomCSS.Content attributes={ attributes } />
57-
<div className={ contentClassNames }>
57+
<div
58+
className={ contentClassNames }
59+
tabIndex={ 0 }
60+
{ ...applyFilters( 'stackable.horizontal-scroller.save.scroller-props', {}, props ) }
61+
>
5862
<InnerBlocks.Content />
5963
</div>
6064
</BlockDiv.Content>

src/block/notification/deprecated.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,26 @@ import {
1414
deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateBlockHeight,
1515
deprecateInnerBlockRowGapAndContainerHeight,
1616
} from '~stackable/block-components'
17+
import { semverCompare } from '~stackable/util'
1718

1819
/**
1920
* WordPress dependencies
2021
*/
22+
23+
import { __ } from '@wordpress/i18n'
2124
import { addFilter } from '@wordpress/hooks'
2225

26+
addFilter( 'stackable.notification.save.close-button-props', 'stackable/3.19.0', ( buttonProps, props ) => {
27+
if ( semverCompare( props.version, '<', '3.19.0' ) ) {
28+
return {
29+
...buttonProps,
30+
'aria-label': undefined,
31+
}
32+
}
33+
34+
return buttonProps
35+
} )
36+
2337
// Version 3.8 added horizontal flex, this changes the stk--block-orientation-* to stk--block-horizontal-flex.
2438
addFilter( 'stackable.notification.save.innerClassNames', 'stackable/3.8.0', ( output, props ) => {
2539
if ( compareVersions( props.version, '3.8.0' ) >= 0 ) {

src/block/notification/save.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SVGCloseIcon from './images/close-icon.svg'
66
/**
77
* External dependencies
88
*/
9-
import { version as VERSION } from 'stackable'
9+
import { version as VERSION, i18n } from 'stackable'
1010
import { withVersion } from '~stackable/higher-order'
1111
import classnames from 'classnames/dedupe'
1212
import {
@@ -22,6 +22,7 @@ import {
2222
/**
2323
* WordPress dependencies
2424
*/
25+
import { __ } from '@wordpress/i18n'
2526
import { InnerBlocks } from '@wordpress/block-editor'
2627
import { compose } from '@wordpress/compose'
2728
import { applyFilters } from '@wordpress/hooks'
@@ -78,6 +79,8 @@ export const Save = props => {
7879
{ attributes.isDismissible &&
7980
<button
8081
className="stk-block-notification__close-button"
82+
aria-label={ __( 'Close', i18n ) }
83+
{ ...applyFilters( 'stackable.notification.save.close-button-props', {}, props ) }
8184
>
8285
<SVGCloseIcon
8386
width={ attributes.dismissibleSize || 16 }

src/block/posts/deprecated.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { createHigherOrderComponent } from '@wordpress/compose'
2323
import { addFilter } from '@wordpress/hooks'
2424
import { select } from '@wordpress/data'
25+
import { semverCompare } from '~stackable/util'
2526

2627
// Version 3.0.2 Deprecations
2728
const addUndefinedAttributes = ( attributes, version ) => {
@@ -36,10 +37,35 @@ const determineFeatureImage = ( featuredImage, version ) => {
3637
return ( compareVersions( '3.6.3', version ) === -1 ) ? featuredImage : <Image.Content />
3738
}
3839

40+
const fixMetaAccessibility = ( output, metaProps, version ) => {
41+
const {
42+
authorShow,
43+
dateShow,
44+
commentsShow,
45+
author,
46+
date,
47+
comments,
48+
separator,
49+
metaClassNames,
50+
} = metaProps
51+
if ( semverCompare( version, '<', '3.19.0' ) ) {
52+
return ( authorShow || dateShow || commentsShow ) && <aside className={ metaClassNames }>
53+
{ authorShow && author }
54+
{ authorShow && author && ( ( dateShow && date ) || ( commentsShow && comments ) ) && separator }
55+
{ dateShow && date }
56+
{ ( ( authorShow && author ) || ( dateShow && date ) ) && commentsShow && comments && separator }
57+
{ commentsShow && comments }
58+
</aside>
59+
}
60+
61+
return output
62+
}
63+
3964
addFilter( 'stackable.posts.title.typography-content', 'stackable/3_0_2', addUndefinedAttributes )
4065
addFilter( 'stackable.posts.title.category-content', 'stackable/3_0_2', addUndefinedAttributes )
4166
addFilter( 'stackable.posts.title.readmore-content', 'stackable/3_0_2', addUndefinedAttributes )
4267
addFilter( 'stackable.posts.feature-image', 'stackable/3_6_3', determineFeatureImage )
68+
addFilter( 'stackable.posts.meta', 'stackable/3.19.0', fixMetaAccessibility )
4369

4470
const deprecated = [
4571
{

src/block/posts/util.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ export const generateRenderPostItem = ( attributes, { isHovered } ) => {
225225
)
226226

227227
const meta = ( authorShow || dateShow || commentsShow ) && (
228-
<aside className={ metaClassNames }>
228+
<div className={ metaClassNames }>
229229
{ authorShow && author }
230230
{ authorShow && author && ( ( dateShow && date ) || ( commentsShow && comments ) ) && separator }
231231
{ dateShow && date }
232232
{ ( ( authorShow && author ) || ( dateShow && date ) ) && commentsShow && comments && separator }
233233
{ commentsShow && comments }
234-
</aside>
234+
</div>
235235
)
236236

237237
const contentFactory = {
@@ -382,15 +382,25 @@ generateRenderPostItem.save = ( attributes, version = VERSION ) => {
382382
/>
383383
)
384384

385-
const meta = ( authorShow || dateShow || commentsShow ) && (
386-
<aside className={ metaClassNames }>
385+
let meta = ( authorShow || dateShow || commentsShow ) && (
386+
<div className={ metaClassNames }>
387387
{ authorShow && author }
388388
{ authorShow && author && ( ( dateShow && date ) || ( commentsShow && comments ) ) && separator }
389389
{ dateShow && date }
390390
{ ( ( authorShow && author ) || ( dateShow && date ) ) && commentsShow && comments && separator }
391391
{ commentsShow && comments }
392-
</aside>
392+
</div>
393393
)
394+
meta = applyFilters( 'stackable.posts.meta', meta, {
395+
authorShow,
396+
dateShow,
397+
commentsShow,
398+
author,
399+
date,
400+
comments,
401+
separator,
402+
metaClassNames,
403+
}, version )
394404

395405
const contentFactory = {
396406
'featured-image': imageShow && featuredImage,

src/block/progress-bar/deprecated.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ import {
77
deprecateTypographyShadowColor, deprecateBlockShadowColor, deprecateContainerShadowColor, deprecateTypographyFontSize,
88
deprecateBlockHeight,
99
} from '~stackable/block-components'
10+
import { semverCompare } from '~stackable/util'
11+
12+
import { addFilter } from '@wordpress/hooks'
13+
14+
const addAriaLabel = ( divProps, props ) => {
15+
if ( semverCompare( props.version, '<', '3.19.0' ) ) {
16+
return {
17+
...divProps,
18+
'aria-label': undefined,
19+
}
20+
}
21+
22+
return divProps
23+
}
24+
25+
addFilter( 'stackable.progress-bar.div-props', 'stackable/3.19.0', addAriaLabel )
1026

1127
const deprecated = [
1228
{

src/block/progress-bar/save.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import classnames from 'classnames'
1414
import striptags from 'striptags'
1515

1616
import { compose } from '@wordpress/compose'
17+
import { applyFilters } from '@wordpress/hooks'
1718

1819
export const Save = props => {
1920
const { className, attributes } = props
@@ -75,6 +76,8 @@ export const Save = props => {
7576
aria-valuemax="100"
7677
aria-valuenow={ progressValue }
7778
aria-valuetext={ derivedAriaValue ? striptags( derivedAriaValue ) : undefined }
79+
aria-label={ derivedAriaValue ? striptags( derivedAriaValue ) : undefined }
80+
{ ...applyFilters( 'stackable.progress-bar.div-props', {}, props ) }
7881
>
7982
<div className={ barClassNames }>
8083
{ attributes.showText && (

0 commit comments

Comments
 (0)