-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] Arrow editing is allowed on a disabled field with enableAccessibleFieldDOMStructure
property
#13387
Comments
enableAccessibleFieldDOMStructure
property
Hey @CodeforEvolution could you please make the sandbox public, so we can have a look at the issue? Thanks! |
My apologies, I just updated the sandbox to be public. |
@CodeforEvolution Thank you for reporting this problem! 🙏 Just clarifying that it's both arrow editing as well as Del, PageUp, PageDown, Home, and End keys. |
enableAccessibleFieldDOMStructure
propertyenableAccessibleFieldDOMStructure
property
This should fix it: --- a/packages/x-date-pickers/src/internals/hooks/useField/useField.ts
+++ b/packages/x-date-pickers/src/internals/hooks/useField/useField.ts
@@ -188,7 +188,7 @@ export const useField = <
case ['ArrowUp', 'ArrowDown', 'Home', 'End', 'PageUp', 'PageDown'].includes(event.key): {
event.preventDefault();
- if (readOnly || activeSectionIndex == null) {
+ if (disabled || readOnly || activeSectionIndex == null) {
break;
} But maybe we want to block all keyboard interactions when disabled --- a/packages/x-date-pickers/src/internals/hooks/useField/useField.ts
+++ b/packages/x-date-pickers/src/internals/hooks/useField/useField.ts
@@ -119,6 +119,10 @@ export const useField = <
const handleContainerKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLSpanElement>) => {
onKeyDown?.(event);
+ if (disabled) {
+ return;
+ }
+
// eslint-disable-next-line default-case
switch (true) { |
Thanks for the diff @flaviendelangle. 🙏 |
Yeah, we clearly lack tests if this was not spotted during the creation of the new DOM structure 😬 @LukasTy do you see a reason not to add the early return? |
I don't see a clear reason not to do it. 🤔 |
@CodeforEvolution: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Steps to reproduce
Link to live example: https://codesandbox.io/p/devbox/vs6gf3?migrateFrom=jtvcqg
Steps:
Current behavior
Despite the DatePicker being disabled, with the enableAccessibleFieldDOMStructure property, the DatePicker will still react to the arrow keys, and even generate onChange events! This behavior is not observed when the enableAccessibleFieldDOMStructure property is not specified.
Expected behavior
The DatePicker should not react to the arrow keys and especially should not generate onChange events in the disabled state, whether the enableAccessibleFieldDOMStructure property is specified or not.
Context
I am using DatePicker in the context of Storybook for automated testing and could benefit from the enableAccessibleFieldDOMStructure property which adds easy to query aria-roles and properties.
Your environment
npx @mui/envinfo
This was tested in both Microsoft Edge and Mozilla Firefox.
Search keywords: enableAccessibleFieldDOMStructure, DatePicker, DesktopDatePicker, disabled
The text was updated successfully, but these errors were encountered: