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

[joy-ui][Button] Disabled style is not applied when component prop is used #38960

Closed
2 tasks done
DiegoAndai opened this issue Sep 13, 2023 · 4 comments · Fixed by #38996
Closed
2 tasks done

[joy-ui][Button] Disabled style is not applied when component prop is used #38960

DiegoAndai opened this issue Sep 13, 2023 · 4 comments · Fixed by #38996
Assignees
Labels
bug 🐛 Something doesn't work component: button This is the name of the generic UI component, not the React module! package: joy-ui Specific to @mui/joy

Comments

@DiegoAndai
Copy link
Member

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/joy-disabled-non-button-t9x84m

Steps:

  1. Use Joy UI Button component
  2. Provide disabled prop
  3. Provide component="a" prop (or any other that's not "button")

Current behavior 😯

The button is disabled (onClick does not fire), but the style does not change accordingly.

Expected behavior 🤔

The button should have the disabled appearance.

Context 🔦

No response

Your environment 🌎

Joy UI v5.0.0-beta.6

@DiegoAndai DiegoAndai added bug 🐛 Something doesn't work component: button This is the name of the generic UI component, not the React module! labels Sep 13, 2023
@danilo-leal danilo-leal changed the title [Button][joy] Disabled style is not applied when component prop is used [joy-ui][Button] Disabled style is not applied when component prop is used Sep 13, 2023
@danilo-leal danilo-leal added the package: joy-ui Specific to @mui/joy label Sep 13, 2023
@sai6855
Copy link
Contributor

sai6855 commented Sep 14, 2023

changing selector from below line &:disabled to &[aria-disabled="true"] worked.

'&:disabled': theme.variants[`${ownerState.variant!}Disabled`]?.[ownerState.color!],

Reason of issue could be because base useButton hook is not adding disabled prop when component is of not button type. we can either add disabled prop for all component types or change css selector.

if (hostElementName === 'BUTTON') {
buttonProps.type = type ?? 'button';
if (focusableWhenDisabled) {
buttonProps['aria-disabled'] = disabled;
} else {
buttonProps.disabled = disabled;
}
} else if (hostElementName !== '') {
if (!href && !to) {
buttonProps.role = 'button';
buttonProps.tabIndex = tabIndex ?? 0;
}
if (disabled) {
buttonProps['aria-disabled'] = disabled as boolean;
buttonProps.tabIndex = focusableWhenDisabled ? tabIndex ?? 0 : -1;
}
}

@DiegoAndai
Copy link
Member Author

DiegoAndai commented Sep 14, 2023

we can either add disabled prop for all component types or change css selector.

The disabled attribute is only supported by a few elements, so I wouldn't change Base's implementation.

Another option, which I think is what we should do, is to use the disabled prop in the Button's ownerState instead of the '&:disabled' selector, something like

- '&:disabled'
+ ownerState.disabled

@sai6855
Copy link
Contributor

sai6855 commented Sep 14, 2023

The disabled attribute is only supported by a few elements, so I wouldn't change Base's implementation.

Ah I see thanks for info, since disabled attribute is supported by multiple elements as shown in mdn doc's. Should base UI also support them instead of just button?

@DiegoAndai
Copy link
Member Author

The hook is useButton, so I think it's fine to only support button for the disabled state until we have a specific case where we need to add the disabled attribute to other elements that support it. This is not such a case as the element might not be one of the ones that support the disabled attribute.

The disabled state is managed on the user side (Joy in this case) and provided to the useButton hook, so the user already has a variable that indicates the disabled state. That's what I propose in this case: use the disabled prop in Joy's Button owner state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: button This is the name of the generic UI component, not the React module! package: joy-ui Specific to @mui/joy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants