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

[TextField] Fix onClick regressions handling changes #38474

Merged
merged 7 commits into from
Aug 22, 2023

Conversation

mj12albert
Copy link
Member

@mj12albert mj12albert commented Aug 14, 2023

Follows up #36892 (comment)

Reverts #38072 and #36892

@mj12albert mj12albert added the component: text field This is the name of the generic UI component, not the React module! label Aug 14, 2023
@mj12albert mj12albert changed the title Revert textfield disabled fixes Revert TextField onClick handling changes Aug 14, 2023
@mui-bot
Copy link

mui-bot commented Aug 14, 2023

Netlify deploy preview

https://deploy-preview-38474--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 886d3d8

@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 14, 2023

We could maybe add test cases, to cover the 2-3 regressions we saw (maybe 1. the one Lukas had, 2. the click bubble issue on TextField 3. the click bubble issue on disabled InputBase).

@oliviertassinari oliviertassinari changed the title Revert TextField onClick handling changes [TextField] Fix onClick regressions handling changes Aug 14, 2023
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work regression A bug, but worse labels Aug 14, 2023
@mj12albert mj12albert force-pushed the revert-textfield-disabled branch 3 times, most recently from 68fd1fd to 009debe Compare August 15, 2023 14:27
Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

For what its worth, LGTM. The revert fixes the relevant issue: mui/mui-x#9386 on X side. 🙌

test/e2e/index.test.ts Show resolved Hide resolved
Comment on lines 241 to 256
it('registers `onClick` on the root slot', () => {
const handleClick = spy();
const { getByTestId } = render(
<TextField
data-testid="root"
onClick={handleClick}
inputProps={{
onClick: handleClick,
}}
/>,
);

const root = getByTestId('root');

fireEvent.click(root);
expect(handleClick.callCount).to.equal(1);
});
Copy link
Member

Choose a reason for hiding this comment

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

This strange looks strange to me. I think the way we test registers onClick on the root slot is by firing the click on the textbox (<input>), adding onClick on the TextField, and checking that event.currentTarget is the root element.

Copy link
Member Author

Choose a reason for hiding this comment

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

@oliviertassinari Thanks for the suggestion ~ I've changed the test to check that instead

(Also removed the "fires only once" test, it's redundant)

@siriwatknp siriwatknp merged commit 4df861a into mui:master Aug 22, 2023
18 checks passed
@mj12albert mj12albert deleted the revert-textfield-disabled branch August 22, 2023 09:45

expect(handleClick.callCount).to.equal(1);
// return value is event.currentTarget
expect(handleClick.returned(root));
Copy link
Member

Choose a reason for hiding this comment

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

This test doesn't work, it doesn't fail without the fix.

This would be correct:

Suggested change
expect(handleClick.returned(root));
expect(handleClick.returned(root)).to.equal(true);

Can we fix it? Thanks

Actually, maybe the assertion itself would be better like this:

Suggested change
expect(handleClick.returned(root));
expect(handleClick.returnValues[0]).to.equal(root);

to give a clearer error message, but so far, we have an issue with our mocha DOM node comparator, it fails to log the diff correctly (another bug)

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: text field This is the name of the generic UI component, not the React module! regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants