Skip to content
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

feat(Button): change behaviour of isDisabled prop #10255

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-core/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ const ButtonBase: React.FunctionComponent<ButtonProps> = ({
<Component
{...props}
{...(isAriaDisabled ? preventedEvents : null)}
aria-disabled={isDisabled || isAriaDisabled}
aria-disabled={isAriaDisabled || (!isButtonElement && isDisabled)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker since overall it doesn't negatively affect anything, but this will always render an aria-disabled prop, sometimes when not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point, there will be the unnecessary aria-disabled="false".
I created a followup issue for this: #10340, if you feel like we don't need this update, you can close it

aria-label={ariaLabel}
className={css(
styles.button,
styles.modifiers[variant],
isBlock && styles.modifiers.block,
isDisabled && styles.modifiers.disabled,
isDisabled && !isButtonElement && styles.modifiers.disabled,
isAriaDisabled && styles.modifiers.ariaDisabled,
isClicked && styles.modifiers.clicked,
isInline && variant === ButtonVariant.link && styles.modifiers.inline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,23 @@ test('Renders with class pf-m-clicked when isClicked = true', () => {
expect(screen.getByRole('button')).toHaveClass('pf-m-clicked');
});

test('Renders with class pf-m-disabled when isDisabled = true', () => {
test('Does not render with class pf-m-disabled by default when isDisabled = true', () => {
render(<Button isDisabled>Disabled Button</Button>);
expect(screen.getByRole('button')).toHaveClass('pf-m-disabled');
expect(screen.getByRole('button')).not.toHaveClass('pf-m-disabled');
});

test('aria-disabled is set to false when isDisabled = true', () => {
render(<Button isDisabled>Disabled Button</Button>);
expect(screen.getByRole('button')).toHaveAttribute('aria-disabled', 'false');
});

test('Renders with class pf-m-disabled when isDisabled = true and component is not a button', () => {
render(
<Button isDisabled component="a">
Disabled Anchor Button
</Button>
);
expect(screen.getByText('Disabled Anchor Button')).toHaveClass('pf-m-disabled');
});

test('Renders with class pf-m-aria-disabled when isAriaDisabled = true', () => {
Expand Down Expand Up @@ -208,7 +222,9 @@ test('aria-disabled is set to true and tabIndex to -1 if component is not a butt
Disabled Anchor Button
</Button>
);
expect(screen.getByText('Disabled Anchor Button')).toHaveAttribute('tabindex', '-1');
const anchor = screen.getByText('Disabled Anchor Button');
expect(anchor).toHaveAttribute('tabindex', '-1');
expect(anchor).toHaveAttribute('aria-disabled', 'true');
});

test('setting tab index through props', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`Renders basic button 1`] = `
aria-disabled="false"
aria-label="basic button"
class="pf-v6-c-button pf-m-primary"
data-ouia-component-id="OUIA-Generated-Button-primary-28"
data-ouia-component-id="OUIA-Generated-Button-primary-30"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ exports[`DualListSelector basic 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Add selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-1"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -163,9 +163,9 @@ exports[`DualListSelector basic 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove all"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-3"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand All @@ -192,9 +192,9 @@ exports[`DualListSelector basic 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-4"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -364,9 +364,9 @@ exports[`DualListSelector basic with disabled controls 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Add selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-13"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand All @@ -393,9 +393,9 @@ exports[`DualListSelector basic with disabled controls 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Add all"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-14"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand All @@ -422,9 +422,9 @@ exports[`DualListSelector basic with disabled controls 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove all"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-15"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand All @@ -451,9 +451,9 @@ exports[`DualListSelector basic with disabled controls 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-16"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -634,9 +634,9 @@ exports[`DualListSelector with actions 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Add selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-21"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -719,9 +719,9 @@ exports[`DualListSelector with actions 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-24"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -956,9 +956,9 @@ exports[`DualListSelector with custom status 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Add selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-9"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -1013,9 +1013,9 @@ exports[`DualListSelector with custom status 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove all"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-11"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand All @@ -1042,9 +1042,9 @@ exports[`DualListSelector with custom status 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-12"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -1256,9 +1256,9 @@ exports[`DualListSelector with search inputs 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Add selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-5"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -1313,9 +1313,9 @@ exports[`DualListSelector with search inputs 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove all"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-7"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand All @@ -1342,9 +1342,9 @@ exports[`DualListSelector with search inputs 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-8"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -1633,9 +1633,9 @@ exports[`DualListSelector with tree 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Add selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-17"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -1690,9 +1690,9 @@ exports[`DualListSelector with tree 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove all"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-19"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand All @@ -1719,9 +1719,9 @@ exports[`DualListSelector with tree 1`] = `
class="pf-v6-c-dual-list-selector__controls-item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Remove selected"
class="pf-v6-c-button pf-m-plain pf-m-disabled"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-20"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ exports[`simple fileupload 1`] = `
class="pf-v6-c-input-group__item"
>
<button
aria-disabled="true"
class="pf-v6-c-button pf-m-control pf-m-disabled"
aria-disabled="false"
class="pf-v6-c-button pf-m-control"
data-ouia-component-id="OUIA-Generated-Button-control-2"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ exports[`numberInput disables lower threshold 1`] = `
class="pf-v6-c-input-group__item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Minus"
class="pf-v6-c-button pf-m-control pf-m-disabled"
class="pf-v6-c-button pf-m-control"
data-ouia-component-id="OUIA-Generated-Button-control-13"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -155,9 +155,9 @@ exports[`numberInput disables upper threshold 1`] = `
class="pf-v6-c-input-group__item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Plus"
class="pf-v6-c-button pf-m-control pf-m-disabled"
class="pf-v6-c-button pf-m-control"
data-ouia-component-id="OUIA-Generated-Button-control-16"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -576,9 +576,9 @@ exports[`numberInput renders disabled 1`] = `
class="pf-v6-c-input-group__item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Minus"
class="pf-v6-c-button pf-m-control pf-m-disabled"
class="pf-v6-c-button pf-m-control"
data-ouia-component-id="OUIA-Generated-Button-control-11"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down Expand Up @@ -627,9 +627,9 @@ exports[`numberInput renders disabled 1`] = `
class="pf-v6-c-input-group__item"
>
<button
aria-disabled="true"
aria-disabled="false"
aria-label="Plus"
class="pf-v6-c-button pf-m-control pf-m-disabled"
class="pf-v6-c-button pf-m-control"
data-ouia-component-id="OUIA-Generated-Button-control-12"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
Expand Down
Loading
Loading