-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add lint rule for inaccessible disabled Button
#62080
Changes from all commits
6ebce5c
cad8b3e
9154483
7040967
7a705eb
cfefecc
bb06929
a5696ec
07b64d3
d94c5fb
0ec3bd9
16ddf06
8e72fa3
fc29ec1
c666444
7e05a82
a111992
b6b9f09
388112f
f4d5ae2
def18f4
8ff5fe9
d188fc5
6f39b75
bca37a2
d16d2b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ export default function InstallButton( { attributes, block, clientId } ) { | |
} | ||
} ) | ||
} | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clearly a busy state, which can cause focus loss. |
||
disabled={ isInstallingBlock } | ||
isBusy={ isInstallingBlock } | ||
variant="primary" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,7 @@ export default function LinkPreview( { | |
isEmptyURL || showIconLabels ? '' : ': ' + value.url | ||
) } | ||
ref={ ref } | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alleviates confusion, since this is a "standard" button usually present in the view. |
||
disabled={ isEmptyURL } | ||
size="compact" | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,13 +222,17 @@ class GalleryImage extends Component { | |
onClick={ isFirstItem ? undefined : onMoveBackward } | ||
label={ __( 'Move image backward' ) } | ||
aria-disabled={ isFirstItem } | ||
// Disable reason: Truly disable when image is not selected. | ||
// eslint-disable-next-line no-restricted-syntax | ||
disabled={ ! isSelected } | ||
/> | ||
<Button | ||
icon={ chevronRight } | ||
onClick={ isLastItem ? undefined : onMoveForward } | ||
label={ __( 'Move image forward' ) } | ||
aria-disabled={ isLastItem } | ||
// Disable reason: Truly disable when image is not selected. | ||
// eslint-disable-next-line no-restricted-syntax | ||
disabled={ ! isSelected } | ||
Comment on lines
224
to
236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering whether a component having both |
||
/> | ||
</ButtonGroup> | ||
|
@@ -237,12 +241,16 @@ class GalleryImage extends Component { | |
icon={ edit } | ||
onClick={ this.onEdit } | ||
label={ __( 'Replace image' ) } | ||
// Disable reason: Truly disable when image is not selected. | ||
// eslint-disable-next-line no-restricted-syntax | ||
disabled={ ! isSelected } | ||
/> | ||
<Button | ||
icon={ closeSmall } | ||
onClick={ onRemove } | ||
label={ __( 'Remove image' ) } | ||
// Disable reason: Truly disable when image is not selected. | ||
// eslint-disable-next-line no-restricted-syntax | ||
disabled={ ! isSelected } | ||
/> | ||
</ButtonGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ export function ConvertToLinksModal( { onClick, onClose, disabled } ) { | |
</Button> | ||
<Button | ||
variant="primary" | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be perceivable, and doesn't clutter tab sequence. |
||
disabled={ disabled } | ||
onClick={ onClick } | ||
> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,6 +338,7 @@ export default function PageListEdit( { | |
<p>{ convertDescription }</p> | ||
<Button | ||
variant="primary" | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be perceivable, especially because the description is always present. |
||
disabled={ ! hasResolvedPages } | ||
onClick={ convertToNavigationLinks } | ||
> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,8 @@ export default function TitleModal( { areaLabel, onClose, onSubmit } ) { | |
<Button | ||
variant="primary" | ||
type="submit" | ||
__experimentalIsFocusable | ||
disabled={ ! title.length } | ||
aria-disabled={ ! title.length } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
> | ||
{ __( 'Create' ) } | ||
</Button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,6 +254,7 @@ function CompactItemActions< Item extends AnyItem >( { | |
size="compact" | ||
icon={ moreVertical } | ||
label={ __( 'Actions' ) } | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a dropdown trigger, so it can potentially cause focus loss. |
||
disabled={ ! actions.length } | ||
className="dataviews-all-actions-button" | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,6 +255,7 @@ function ListItem< Item extends AnyItem >( { | |
size="compact" | ||
icon={ moreVertical } | ||
label={ __( 'Actions' ) } | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An empty action menu should still be perceivable to alleviate confusion, and does not clutter tab sequence due to |
||
disabled={ ! actions.length } | ||
onKeyDown={ ( event: { | ||
key: string; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ export function CustomFieldsConfirmation( { willEnable } ) { | |
className="edit-post-preferences-modal__custom-fields-confirmation-button" | ||
variant="secondary" | ||
isBusy={ isReloading } | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clearly a busy state, which can cause focus loss. |
||
disabled={ isReloading } | ||
onClick={ () => { | ||
setIsReloading( true ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,7 @@ function RevisionsButtons( { | |
> | ||
<Button | ||
className="edit-site-global-styles-screen-revisions__revision-button" | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This button can contain a lot of important information and should be perceivable even when disabled. |
||
disabled={ isSelected } | ||
onClick={ () => { | ||
onChange( revision ); | ||
|
@@ -219,7 +220,6 @@ function RevisionsButtons( { | |
</p> | ||
) : ( | ||
<Button | ||
disabled={ areStylesEqual } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed that this can and should be removed because |
||
size="compact" | ||
variant="primary" | ||
className="edit-site-global-styles-screen-revisions__apply-button" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ export default function RenameModal( { menuTitle, onClose, onSave } ) { | |
|
||
<Button | ||
__next40pxDefaultSize | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be perceivable to signal that the user input is invalid. |
||
disabled={ ! isEditedMenuTitleValid } | ||
variant="primary" | ||
type="submit" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,7 @@ export default function PostPreviewButton( { | |
className={ className || 'editor-post-preview' } | ||
href={ href } | ||
target={ targetId } | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be perceivable, because the button is expected to be there. |
||
disabled={ ! isSaveable } | ||
onClick={ openPreviewWindow } | ||
role={ role } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,12 +139,16 @@ describe( 'PostPreviewButton', () => { | |
).toBeInTheDocument(); | ||
} ); | ||
|
||
it( 'should be disabled if post is not saveable.', () => { | ||
it( 'should be accessibly disabled if post is not saveable.', () => { | ||
mockUseSelect( { isEditedPostSaveable: () => false } ); | ||
|
||
render( <PostPreviewButton /> ); | ||
|
||
expect( screen.getByRole( 'button' ) ).toBeDisabled(); | ||
expect( screen.getByRole( 'button' ) ).toBeEnabled(); | ||
expect( screen.getByRole( 'button' ) ).toHaveAttribute( | ||
'aria-disabled', | ||
'true' | ||
); | ||
Comment on lines
+148
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the recommended way to test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe we can keep both assertions as they check for different things? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes a lot of sense, actually. Addressed in bca37a2. |
||
} ); | ||
|
||
it( 'should not be disabled if post is saveable.', () => { | ||
|
@@ -153,6 +157,10 @@ describe( 'PostPreviewButton', () => { | |
render( <PostPreviewButton /> ); | ||
|
||
expect( screen.getByRole( 'button' ) ).toBeEnabled(); | ||
expect( screen.getByRole( 'button' ) ).not.toHaveAttribute( | ||
'aria-disabled', | ||
'true' | ||
); | ||
} ); | ||
|
||
it( 'should set `href` to edited post preview link if specified.', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ export class PostPublishPanel extends Component { | |
</div> | ||
<div className="editor-post-publish-panel__header-cancel-button"> | ||
<Button | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can cause focus loss due to a dynamic disable. |
||
disabled={ isSavingNonPostEntityChanges } | ||
onClick={ onClose } | ||
variant="secondary" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ function ImportForm( { instanceId, onUpload } ) { | |
<Button | ||
type="submit" | ||
isBusy={ isLoading } | ||
__experimentalIsFocusable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be perceivable, and can cause focus loss. |
||
disabled={ ! file || isLoading } | ||
variant="secondary" | ||
className="list-reusable-blocks-import-form__button" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that the rule works well 👍