Skip to content

Commit 695b9a1

Browse files
author
Eric Olkowski
committed
fix(Button): reverted aria-disabled logic
1 parent fb25d76 commit 695b9a1

File tree

43 files changed

+273
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+273
-6
lines changed

packages/react-core/src/components/AboutModal/__tests__/__snapshots__/AboutModalBoxCloseButton.test.tsx.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`AboutModalBoxCloseButton Test 1`] = `
66
class="pf-v6-c-about-modal-box__close"
77
>
88
<button
9+
aria-disabled="false"
910
aria-label="Close Dialog"
1011
class="pf-v6-c-button pf-m-plain"
1112
data-ouia-component-id="OUIA-Generated-Button-plain-1"
@@ -41,6 +42,7 @@ exports[`AboutModalBoxCloseButton Test close button aria label 1`] = `
4142
class="pf-v6-c-about-modal-box__close"
4243
>
4344
<button
45+
aria-disabled="false"
4446
aria-label="Klose Daylok"
4547
class="pf-v6-c-button pf-m-plain"
4648
data-ouia-component-id="OUIA-Generated-Button-plain-3"
@@ -76,6 +78,7 @@ exports[`AboutModalBoxCloseButton Test onclose 1`] = `
7678
class="pf-v6-c-about-modal-box__close"
7779
>
7880
<button
81+
aria-disabled="false"
7982
aria-label="Close Dialog"
8083
class="pf-v6-c-button pf-m-plain"
8184
data-ouia-component-id="OUIA-Generated-Button-plain-2"

packages/react-core/src/components/Alert/__tests__/Generated/__snapshots__/AlertActionCloseButton.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`AlertActionCloseButton should match snapshot 1`] = `
44
<DocumentFragment>
55
<button
6+
aria-disabled="false"
67
aria-label="Close some label alert: test title"
78
class="pf-v6-c-button pf-m-plain"
89
data-ouia-component-id="OUIA-Generated-Button-plain-1"

packages/react-core/src/components/Alert/__tests__/Generated/__snapshots__/AlertActionLink.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`AlertActionLink should match snapshot (auto-generated) 1`] = `
44
<DocumentFragment>
55
<button
6+
aria-disabled="false"
67
class="pf-v6-c-button pf-m-link pf-m-inline ''"
78
data-ouia-component-id="OUIA-Generated-Button-link-1"
89
data-ouia-component-type="PF6/Button"

packages/react-core/src/components/Button/Button.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,12 @@ const ButtonBase: React.FunctionComponent<ButtonProps> = ({
164164
</span>
165165
);
166166
const _children = children && <span className={css('pf-v6-c-button__text')}>{children}</span>;
167-
// We only want to render the aria-disabled attribute when true, similar to the disabled attribute natively.
168-
const shouldRenderAriaDisabled = isAriaDisabled || (!isButtonElement && isDisabled);
169167

170168
return (
171169
<Component
172170
{...props}
173171
{...(isAriaDisabled ? preventedEvents : null)}
174-
{...(shouldRenderAriaDisabled && { 'aria-disabled': true })}
172+
aria-disabled={isAriaDisabled || isDisabled}
175173
aria-label={ariaLabel}
176174
className={css(
177175
styles.button,

packages/react-core/src/components/Button/__tests__/Button.test.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,33 @@ test('Renders with class pf-m-disabled when isDisabled = true and component is n
7373
expect(screen.getByText('Disabled Anchor Button').parentElement).toHaveClass('pf-m-disabled');
7474
});
7575

76-
test(`aria-disabled and class ${styles.modifiers.ariaDisabled} are not rendered when isAriaDisabled is not passed by default`, () => {
76+
// Re-enable as part of https://github.com/patternfly/patternfly-react/issues/11618
77+
test.skip(`aria-disabled and class ${styles.modifiers.ariaDisabled} are not rendered when isAriaDisabled is not passed by default`, () => {
7778
render(<Button>Button</Button>);
7879

7980
const button = screen.getByRole('button');
8081
expect(button).not.toHaveAttribute('aria-disabled');
8182
expect(button).not.toHaveClass(styles.modifiers.ariaDisabled);
8283
});
8384

84-
test(`aria-disabled and class ${styles.modifiers.ariaDisabled} are not rendered when isDisabled is true, but isAriaDisabled is not passed`, () => {
85+
// Re-enable as part of https://github.com/patternfly/patternfly-react/issues/11618
86+
test.skip(`aria-disabled and class ${styles.modifiers.ariaDisabled} are not rendered when isDisabled is true, but isAriaDisabled is not passed`, () => {
8587
render(<Button isDisabled>Disabled Button</Button>);
8688

8789
const button = screen.getByRole('button');
8890
expect(button).not.toHaveAttribute('aria-disabled');
8991
expect(button).not.toHaveClass(styles.modifiers.ariaDisabled);
9092
});
9193

94+
// Remove as part of https://github.com/patternfly/patternfly-react/issues/11618
95+
test(`Renders with aria-disabled of true and without class ${styles.modifiers.ariaDisabled} when isDisabled is true`, () => {
96+
render(<Button isDisabled>Disabled Button</Button>);
97+
98+
const button = screen.getByRole('button');
99+
expect(button).toHaveAttribute('aria-disabled', 'true');
100+
expect(button).not.toHaveClass(styles.modifiers.ariaDisabled);
101+
});
102+
92103
test(`Renders with class ${styles.modifiers.ariaDisabled} and aria-disabled attribute when isAriaDisabled = true`, () => {
93104
render(<Button isAriaDisabled>Disabled yet focusable button</Button>);
94105
const button = screen.getByRole('button');

packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
exports[`Renders basic button 1`] = `
44
<DocumentFragment>
55
<button
6+
aria-disabled="false"
67
aria-label="basic button"
78
class="pf-v6-c-button pf-m-primary"
8-
data-ouia-component-id="OUIA-Generated-Button-primary-31"
9+
data-ouia-component-id="OUIA-Generated-Button-primary-30"
910
data-ouia-component-type="PF6/Button"
1011
data-ouia-safe="true"
1112
type="button"

packages/react-core/src/components/Card/__tests__/__snapshots__/CardHeader.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exports[`CardHeader onExpand adds the toggle button 1`] = `
2121
class="pf-v6-c-card__header-toggle"
2222
>
2323
<button
24+
aria-disabled="false"
2425
class="pf-v6-c-button pf-m-plain"
2526
data-ouia-component-id="OUIA-Generated-Button-plain-1"
2627
data-ouia-component-type="PF6/Button"

packages/react-core/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopyButton.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ exports[`Matches snapshot 1`] = `
2828
onTooltipHidden clicker
2929
</a>
3030
<button
31+
aria-disabled="false"
3132
aria-label="Copyable input"
3233
aria-labelledby="button-id text-id"
3334
class="pf-v6-c-button pf-m-control"

packages/react-core/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopyToggle.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`Matches snapshot 1`] = `
44
<DocumentFragment>
55
<button
66
aria-controls="content-id"
7+
aria-disabled="false"
78
aria-expanded="false"
89
aria-labelledby="main-id text-id"
910
class="pf-v6-c-button pf-m-control"

packages/react-core/src/components/DataList/__tests__/Generated/__snapshots__/DataListToggle.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exports[`DataListToggle should match snapshot (auto-generated) 1`] = `
1111
>
1212
<button
1313
aria-controls="''"
14+
aria-disabled="false"
1415
aria-expanded="false"
1516
aria-label="'Details'"
1617
class="pf-v6-c-button pf-m-plain"

0 commit comments

Comments
 (0)