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

ListItemButton will not set DOM disabled attribute #35779

Closed
2 tasks done
tlthiem opened this issue Jan 10, 2023 · 2 comments
Closed
2 tasks done

ListItemButton will not set DOM disabled attribute #35779

tlthiem opened this issue Jan 10, 2023 · 2 comments
Assignees
Labels
component: button This is the name of the generic UI component, not the React module! status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it

Comments

@tlthiem
Copy link

tlthiem commented Jan 10, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example: https://codesandbox.io/s/mui-list-item-button-not-disabled-yzqz67

Steps:

  1. inspect both buttons
  2. the normal mui Button has disabled DOM attribute
    3.the ListItemButton only has aria-disabled attribute. Styles are correct.

Current behavior 😯

The ListItemButton does not apply the disabled attribute to the DOM element when disabled via prop.

Expected behavior 🤔

Just like the mui Button component the disabled attribute is set in DOM.
If this is expected behaviour I would expect this to be documented.

Context 🔦

This came up during component testing.

expect(component).toBeDisabled(); will throw.

Your environment 🌎

System:
OS: Windows 10 10.0.22000
Binaries:
Node: 16.19.0
Yarn: 3.2.0
npm: 8.19.3
Browsers:
Chrome: Not Found
Edge: Spartan (44.22000.120.0), Chromium (108.0.1462.54)

@tlthiem tlthiem added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 10, 2023
@zannager zannager added the component: button This is the name of the generic UI component, not the React module! label Jan 10, 2023
@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Jan 11, 2023

The ListItemButton is rendered as a div, and <div> elements do not have a disabled attribute according to the HTML docs. Hence, it is not forwarded to the DOM.

In your test you can assert with the aria-disabled attribute:

expect(component).toHaveAttribute('aria-disabled', 'true')

as mentioned in testing-library/jest-dom#144 (comment).

@ZeeshanTamboli ZeeshanTamboli removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 11, 2023
@ZeeshanTamboli ZeeshanTamboli added the status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it label Jan 11, 2023
@siriwatknp
Copy link
Member

This makes me think why ListItemButton does not use button by default 🤔.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: button This is the name of the generic UI component, not the React module! status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it
Projects
None yet
Development

No branches or pull requests

5 participants