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

[NumberField] Fix disabled state on increment/decrement buttons #1462

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mj12albert
Copy link
Member

@mj12albert mj12albert commented Feb 18, 2025

Fixes #1443

Before: https://codesandbox.io/p/sandbox/cocky-kepler-y5j9tz

After: https://codesandbox.io/p/devbox/billowing-cookies-gnsfn5

The issue was that pointer event handlers didn't consider the disabled prop on the buttons, only other disabled states (e.g. root)

@mj12albert mj12albert added component: number field This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work labels Feb 18, 2025
Copy link

netlify bot commented Feb 18, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 50893ee
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/67b4673c5f16290008f37ff5
😎 Deploy Preview https://deploy-preview-1462--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mj12albert mj12albert marked this pull request as ready for review February 18, 2025 11:04
@@ -315,4 +316,22 @@ describe('<NumberField.Decrement />', () => {

expect(input).to.have.value('-2');
});

it('prop: disabled', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: the it function should describe the correct behavior. We usually place "prop: X" on the describe blocks.

@@ -452,7 +452,8 @@ export function useNumberFieldRoot(
},
onPointerDown(event) {
const isMainButton = !event.button || event.button === 0;
const isDisabled = disabled || (isIncrement ? isMax : isMin);
const isDisabled =
(externalProps.disabled ?? false) || disabled || (isIncrement ? isMax : isMin);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely comfortable with this pattern. Not because it produces wrong results, but because we generally never rely on anything from externalProps. Is there a good reason for keeping all the buttons' handlers in the root hook instead of moving them closer to components?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a good reason for keeping all the buttons' handlers in the root hook instead of moving them closer to components?

Yeah I agree, I thought reaching into externalProps was starting to get weird 😅
Probably this was the earliest rewritten component and later we moved to have them closer to components, do you think its ok to move this to its own hook now @atomiks ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this was written before we moved hooks/logic into their owning components - it's okay to change it to follow the latest patterns

@mj12albert mj12albert removed the request for review from colmtuite February 20, 2025 06:00
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: number field This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NumberField] Increment and Decrement can be clicked when disabled
3 participants