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

[fields] Use onChange instead of onKeyPress for Backspace editing #10494

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Sep 27, 2023

Fixes #10399

After some more investigation, the problem is that the Backspace key is always treated as Unidentified on Android, so it was edited using onChange.
I updated the onChange to work with Backspace editing, removed the Backspace editing from onKeyPress and updated all the tests.

@flaviendelangle flaviendelangle added bug 🐛 Something doesn't work component: pickers This is the name of the generic UI component, not the React module! labels Sep 27, 2023
@flaviendelangle flaviendelangle self-assigned this Sep 27, 2023
@@ -213,6 +213,10 @@ export const useFieldState = <
tempValueStrAndroid: null,
}));

if (valueManager.areValuesEqual(utils, state.value, value)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Before, we were not even calling publishValue.
But it's problematic with Backspace because the state was not updated when pressing Backspace on an already empty section, causing the selection to be removed by the browser.
So now we always update the state but we don't publish onChange if not needed

const activeDateManager = fieldValueManager.getActiveDateManager(utils, state, activeSection);

const nonEmptySectionCountBefore = activeDateManager
.getSections(state.sections)
.filter((section) => section.value !== '').length;
const isTheOnlyNonEmptySection = nonEmptySectionCountBefore === 1;
const hasNoOtherNonEmptySections =
Copy link
Member Author

Choose a reason for hiding this comment

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

Small fix when the active section is already empty
If could never happen before

@mui-bot
Copy link

mui-bot commented Sep 27, 2023

Deploy preview: https://deploy-preview-10494--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 797d1ab

@flaviendelangle flaviendelangle changed the title [fields] Use onChange instead of onKeyPress for Backspace editing [fields] Use onChange instead of onKeyPress for Backspace editing Sep 27, 2023
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.

Great work! 💯
This has the added benefit of now allowing the full date clearing.
Previously clicking Backspace on Android while having the whole field selected would not correctly clear the field 🙈

I noticed that after these changes there is some sort of flickering happening when deleting a section value on Android, it also happens when trying to delete already empty section.
It seems that visually the section value gets removed and then added back in.
Is there any way we could avoid this, because the UX is not the best now. 🙈

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 12, 2023
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@flaviendelangle
Copy link
Member Author

flaviendelangle commented Oct 16, 2023

I noticed that after these changes there is some sort of flickering happening when deleting a section value on Android, it also happens when trying to delete already empty section.

I I understand the flickering you are talking about, thenI also have the flickering on master
And I did not find a way to fix it when I first did the Android support last year:

// If `state.tempValueStrAndroid` is still defined when running `useEffect`,
// Then `onChange` has only been called once, which means the user pressed `Backspace` to reset the section.
// This causes a small flickering on Android,
// But we can't use `useEnhancedEffect` which is always called before the second `onChange` call and then would cause false positives.

I do agree that it's not optimal
In v6 since the section will be alone in its input, the sections further right won't move 👌

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 16, 2023
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.

Sorry for missing the mentioned comment. 🙈
Yeah, it's definitely not a big problem, it's not that you constantly need to delete already empty sections. 😆

@flaviendelangle
Copy link
Member Author

The mentionned comment is in the middle of thousands of lines of code, not easy to spot 👌

@flaviendelangle flaviendelangle merged commit 574ce72 into mui:master Oct 16, 2023
5 checks passed
@flaviendelangle flaviendelangle deleted the android-backspace branch October 16, 2023 11:31
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: pickers 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.

[DateField] LL format allows for removing MMMM placeholder resulting in issues when filling in a date.
3 participants