[interactive elements] remove duplicated disabled prop#3650
[interactive elements] remove duplicated disabled prop#3650atomiks merged 7 commits intomui:masterfrom
Conversation
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
When Additionally, when the |
| @@ -63,7 +63,7 @@ export const NumberFieldIncrement = React.forwardRef(function NumberFieldIncreme | |||
| maxWithDefault, | |||
| value, | |||
| inputValue, | |||
| disabled, | |||
| disabled: composedDisabled, | |||
There was a problem hiding this comment.
Thanks for the fixes - what is this particular file (and Decrement) changed for?
There was a problem hiding this comment.
As with other components, it appropriately merges the disabled passed from the Root component and the disabled passed from the Increment component.
And unlike other components, NumberField recalculates disabled within useNumberFieldButton. Therefore, it separately creates composedDisabled. If declaring this variable is unnecessary, directly assigning it as shown below is also valid.
const { disabled = false, ...props } = useNumberFieldButton({
// ....
disabled: disabledProp || contextDisabled,
});There was a problem hiding this comment.
Ah I see that you're checking the result of the internal calculation:
disabled: disabled || (isIncrement ? isMax : isMin),I would do this calculation before passing to useNumberFieldButton, that way it's composed of all the states and NumberFieldIncrement.State has the correct disabled state, without needing the destructure props collection?
Furthermore, I realized that the Number Field buttons should use focusableWhenDisabled: true in useButton so focus isn't lost when it reaches the min/max value.
There was a problem hiding this comment.
Before passing it to the useNumberFieldButton hook, completing the calculation of the disabled property would look like this:
const composedDisabled = disabledProp || contextDisabled;
const isMax = value != null && value >= maxWithDefault;
```ts
const { disabled = false, ...props } = useNumberFieldButton({
// ...
disabled: composedDisabled || isMax,
});However, doing this might allow the isDisabled value to change when calculated inside useNumberFieldButton.
// current
const isDisabled = disabled || readOnly || (isIncrement ? isMax : isMin);
// changed
const isDisabled = disabled || readOnly;But I don't think this difference is particularly significant. So, I think it would be okay to change the internal logic of the useNumberFieldButton hook. What do you think?
There was a problem hiding this comment.
Yes, it's better as it reduces the repetition in the event handlers
It should look like this:
const isMax = value != null && value >= maxWithDefault;
const disabled = disabledProp || contextDisabled || isMax;
const props = useNumberFieldButton({
disabled,
});Then internally,
const isDisabled = disabled || readOnly;Since disabled has the min/max condition
There was a problem hiding this comment.
Thank you for your feedback. I did it here
atomiks
left a comment
There was a problem hiding this comment.
Thank you - pnpm prettier needs to be run
|
I did it here! |
getButtonPropsselects and applies eitherdisabledoraria-disabledappropriately. But thedisabledattribute was always being added separately, meaning it was always present regardless.Fixes #3649