Skip to content

Commit

Permalink
This PR removes the button that loads the global revision and moves i…
Browse files Browse the repository at this point in the history
…t up to an accessible list item.

The result is that the list item is tabbable and selectable via keyboard, and the focus state wraps the entire item.
  • Loading branch information
ramonjd committed Nov 6, 2024
1 parent 7f49b39 commit 0c39e3b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
Expand All @@ -12,7 +7,7 @@ import { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';

import { ENTER, SPACE } from '@wordpress/keycodes';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -120,7 +115,7 @@ function RevisionsButtons( {
<ol
className="edit-site-global-styles-screen-revisions__revisions-list"
aria-label={ __( 'Global styles revisions list' ) }
role="group"
role="listbox"
>
{ userRevisions.map( ( revision, index ) => {
const { id, author, modified } = revision;
Expand Down Expand Up @@ -150,27 +145,24 @@ function RevisionsButtons( {

return (
<li
className={ clsx(
'edit-site-global-styles-screen-revisions__revision-item',
{
'is-selected': isSelected,
'is-active': areStylesEqual,
'is-reset': isReset,
}
) }
className="edit-site-global-styles-screen-revisions__revision-item"
key={ id }
aria-current={ isSelected }
>
<Button
__next40pxDefaultSize
className="edit-site-global-styles-screen-revisions__revision-button"
accessibleWhenDisabled
disabled={ isSelected }
onClick={ () => {
tabIndex={ 0 }
role="option"
onKeyDown={ ( event ) => {
const { keyCode } = event;
if ( keyCode === ENTER || keyCode === SPACE ) {
onChange( revision );
} }
aria-label={ revisionLabel }
>
}
} }
onClick={ () => {
onChange( revision );
} }
aria-selected={ isSelected }
aria-label={ revisionLabel }
>
<span className="edit-site-global-styles-screen-revisions__revision-item-wrapper">
{ isReset ? (
<span className="edit-site-global-styles-screen-revisions__description">
{ __( 'Default styles' ) }
Expand Down Expand Up @@ -211,7 +203,7 @@ function RevisionsButtons( {
) }
</span>
) }
</Button>
</span>
{ isSelected &&
( areStylesEqual ? (
<p className="edit-site-global-styles-screen-revisions__applied-text">
Expand All @@ -225,6 +217,9 @@ function RevisionsButtons( {
variant="primary"
className="edit-site-global-styles-screen-revisions__apply-button"
onClick={ onApplyRevision }
aria-label={ __(
'Apply the selected revision to your site.'
) }
>
{ isReset
? __( 'Reset to defaults' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
display: flex;
flex-direction: column;

&[role="option"]:active,
&[role="option"]:focus {
//@include block-toolbar-button-style__focus();
@include input-style__focus();
}

&:hover {
background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
.edit-site-global-styles-screen-revisions__date {
Expand Down Expand Up @@ -42,7 +48,7 @@
border: 4px solid transparent;
}

&.is-selected {
&[aria-selected="true"] {
border-radius: $radius-small;

// Only visible in Windows High Contrast mode.
Expand All @@ -52,10 +58,6 @@
color: var(--wp-admin-theme-color);
background: rgba(var(--wp-admin-theme-color--rgb), 0.04);

.edit-site-global-styles-screen-revisions__revision-button {
opacity: 1;
}

.edit-site-global-styles-screen-revisions__date {
color: var(--wp-admin-theme-color);
}
Expand Down Expand Up @@ -86,23 +88,16 @@
&:last-child::after {
height: $grid-unit-20 + 2;
}

// Nested to override specificity of .components-button.
.edit-site-global-styles-screen-revisions__revision-button {
width: 100%;
height: auto;
display: block;
padding: $grid-unit-15 $grid-unit-15 $grid-unit-05 $grid-unit-50;
z-index: 1;
position: relative;
outline-offset: -2px;
}
}
.edit-site-global-styles-screen-revisions__revision-item-wrapper {
display: block;
padding: $grid-unit-15 $grid-unit-15 $grid-unit-05 $grid-unit-50;
}

.edit-site-global-styles-screen-revisions__apply-button.is-primary,
.edit-site-global-styles-screen-revisions__applied-text {
align-self: flex-start;
// Left margin = left padding of .edit-site-global-styles-screen-revisions__revision-button.
// Left margin = left padding of .edit-site-global-styles-screen-revisions__revision-item-wrapper.
margin: $grid-unit-05 $grid-unit-15 $grid-unit-15 $grid-unit-50;
}

Expand Down

0 comments on commit 0c39e3b

Please sign in to comment.