Skip to content

Commit

Permalink
Update horizontal slider and image to be more accessible. (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenDufresne authored Oct 19, 2022
1 parent 2e08cd1 commit 7186a8a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
1 change: 1 addition & 0 deletions mu-plugins/blocks/horizontal-slider/postcss/style.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ button[disabled]::after {
gap: 12px;
padding-bottom: 24px;
padding-top: 6px;
list-style: none;

/* So item focus states are not clipped */
margin-left: -4px;
Expand Down
32 changes: 18 additions & 14 deletions mu-plugins/blocks/horizontal-slider/src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ function Block( { items, title } ) {
return (
<div>
<div className="horizontal-slider-header">
<span>
<h3 className="horizontal-slider-title">{ title }</h3>
</span>
<h3 className="horizontal-slider-title">{ title }</h3>
{ ( canNext || canPrevious ) && (
<span className="horizontal-slider-controls">
<Handle
Expand All @@ -115,19 +113,25 @@ function Block( { items, title } ) {
</span>
) }
</div>
<div className="horizontal-slider-wrapper" ref={ outerRef }>
<ul className="horizontal-slider-wrapper" ref={ outerRef } role="tablist">
{ items.map( ( item ) => (
<ScreenShot
key={ item.title }
{ ...item }
width={ `${ width }px` }
height={ `${ height }px` }
aspectRatio={ aspectRatio }
queryString={ `?vpw=${ initialWidth * 10 }&vph=${ initialHeight * 10 }` }
isReady={ true }
/>
<li key={ item.title } role="presentation">
<ScreenShot
{ ...item }
width={ `${ width }px` }
height={ `${ height }px` }
aspectRatio={ aspectRatio }
queryString={ `?vpw=${ initialWidth * 10 }&vph=${ initialHeight * 10 }` }
isReady={ true }
anchorTagProps={ {
'aria-controls': item.title,
'aria-selected': false,
role: 'tab',
} }
/>
</li>
) ) }
</div>
</ul>
</div>
);
}
Expand Down
20 changes: 11 additions & 9 deletions mu-plugins/blocks/screenshot-preview/src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import ScreenShot from './screenshot';
/**
*
* @param {Object} props
* @param {string} props.link Url for anchor tag.
* @param {string} props.previewLink Url used for the screenshot preview.
* @param {string} props.caption Text for screen readers.
* @param {string} props.height Initial height for the preview, include unit.
* @param {string} props.width Desired with of the preview element, include unit.
* @param {number} props.aspectRatio Aspect ratio for the preview element.
* @param {string} props.queryString Arguments passed to screenshot service.
* @param {string} props.link Url for anchor tag.
* @param {string} props.previewLink Url used for the screenshot preview.
* @param {string} props.caption Text for screen readers.
* @param {string} props.height Initial height for the preview, include unit.
* @param {string} props.width Desired with of the preview element, include unit.
* @param {number} props.aspectRatio Aspect ratio for the preview element.
* @param {string} props.queryString Arguments passed to screenshot service.
* @param {Object} props.anchorTagProps HTMLAnchorElement attributes to be added to the block anchor tag.
*
* @return {Object} React element
*/
Expand All @@ -31,6 +32,7 @@ function Block( {
width = '100%',
aspectRatio = 2 / 3,
queryString = '?vpw=1200&vph=800',
anchorTagProps = {},
} ) {
const wrapperRef = useRef();
const [ frameHeight, setFrameHeight ] = useState( height );
Expand Down Expand Up @@ -68,9 +70,9 @@ function Block( {
width: width,
} }
href={ link }
{ ...anchorTagProps }
>
{ caption && <span className="screen-reader-text">{ caption }</span> }
<ScreenShot queryString={ queryString } src={ previewLink } isReady={ shouldLoad } />
<ScreenShot queryString={ queryString } src={ previewLink } isReady={ shouldLoad } alt={ caption } />
</a>
);
}
Expand Down
5 changes: 3 additions & 2 deletions mu-plugins/blocks/screenshot-preview/src/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ function useInterval( callback, delay ) {
* we need to do some custom handling.
*
* @param {Object} props
* @param {string} props.alt Alternate text for image.
* @param {string} props.queryString Arguments that are passed to mShots.
* @param {string} props.src The url of the screenshot.
* @param {boolean} props.isReady Whether we should start try to show the image.
*
* @return {Object} React component
*/
function ScreenShotImg( { queryString, src, isReady = false } ) {
function ScreenShotImg( { alt = '', queryString, src, isReady = false } ) {
const fullUrl = `https://s0.wp.com/mshots/v1/${ encodeURIComponent( src ) }${ queryString }`;

const [ attempts, setAttempts ] = useState( 0 );
Expand Down Expand Up @@ -112,7 +113,7 @@ function ScreenShotImg( { queryString, src, isReady = false } ) {
return <div className="wporg-screenshot wporg-screenshot__has-error">{ __( 'error', 'wporg' ) }</div>;
}

return <img src={ base64Img } alt="" />;
return <img src={ base64Img } alt={ alt } />;
}

export default ScreenShotImg;

0 comments on commit 7186a8a

Please sign in to comment.