fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

DatePicker - Calendar pop up is not open on click is 'disableAutoFocus' prop is set to true.

Open Hugodol opened this issue 7 years ago • 9 comments

Environment Information

  • Package version(s): 7.60.0

Please provide a reproduction of the bug in a codepen: https://codepen.io/hugodol/pen/oNNaxpG

Actual behavior:

When the DatePicker component has the 'disableAutoFocus' prop set to true, the onClick event for the text field does not trigger the calendar pop up to open. This is the current code in DatePicker.base.tsx that is causing the issue (located on line 372): private _onTextFieldClick = (ev: React.MouseEvent<HTMLElement>): void => { if (!this.props.disableAutoFocus && !this.state.isDatePickerShown && !this.props.disabled) { this._showDatePickerPopup(); return; } if (this.props.allowTextInput) { this._dismissDatePickerPopup(); } };

Expected behavior:

The calendar pop up should be triggered when the text field is clicked regardless of the 'disableAutoFocus' prop.

Priorities and help @requested:

Requested priority: High

Products/sites affected: Assignments in Microsoft Teams

Hugodol avatar Nov 13 '19 21:11 Hugodol

@lorejoh12 - John, mind if you take a look at this?

kenotron avatar Nov 13 '19 22:11 kenotron

@Hugodol FYI, this change was made deliberately as part of #10913

onlyann avatar Nov 23 '19 11:11 onlyann

@onlyann That seems very limiting when allowTextInput is not set to true. If nothing happens when the input is clicked, it appears to be broken.

Hugodol avatar Nov 25 '19 17:11 Hugodol

@Hugodol What is the scenario where one might want disableAutoFocus={true} as well as allowTextInput={false}?

I am personally on the fence with the change done as part of #10913.

On the one hand, the new behaviour improves the user experience for keyboard users because the input focus is not stolen by the popup on click ( and as per the original intent, fixes some iOS problem).

On the other hand, it does it in such a way that it only shows the popup when the user clicks on the icon, as opposed to anywhere on the picker.

I would have liked that the popup continues to open when clicking anywhere on the picker without stealing focus.

Maybe DatePicker should offer an optional prop that controls the popup visibility.

onlyann avatar Nov 26 '19 02:11 onlyann

@onlyann We essentially use the component has a button that only shows the popup when activated by the user (whether use keyboard nav or mouse). We find the popup automatically showing disruptive for keyboard navigation but we don't want to allow text input.

Hugodol avatar Nov 26 '19 17:11 Hugodol

Thanks for the quick feedback and context @onlyann

From our perspective, the combination of AutoFocus + FocusZoneTrap creates a barrier for keyboard users accessing elements displayed under the DatePicker. You shouldn't be forced to "ESC" out of a popup in order to reach an input at the bottom of the page.

From a higher, component interface level, I think it's reasonable to say that only allowTextInput should affect the onClick behavior of the DatePicker. It seems like a bug to me that disableAutoFocus is related to onClick at all.

IMHO, the issue on iOS could be better served with props that disable pop-up/focus

cjsheets avatar Nov 26 '19 17:11 cjsheets

I agree that disableAutoFocus logic should be implemented with an onFocus handler, not onClick. An element can be focused in ways other than clicking. For example, tabbing to it with a keyboard, or when iOS VoiceOver automatically focuses on it when focus is lost from an adjacent element.

There should be separate logic for onClick of the text field to toggle the dropdown. By onClick, I really mean activate, which covers Enter key, mouse click, touch tap, etc. This is tricky to coordinate with the onFocus handler so that the dropdown is not toggled twice, but is possible.

As for focus trapping, I believe this behavior is intentional. For dropdowns, there are two treatments to make them accessible.

  1. Modal. Hide everything except the dropdown with aria-hidden so that screen reader users cannot navigate outside the dropdown. Trap focus inside dropdown so that keyboard users cannot navigate to background contents. The only way to exit is to select a value, click outside the dropdown with a pointer device, press Escape, or hit a Cancel button.
  2. Non-modal. Keyboard users can navigate to the next control by pressing TAB. Touch screen readers can swipe left or right to navigate out of the dropdown without closing it. Same with keyboard screen readers and arrow keys.

Approach 2 requires the dropdown to be adjacent to the text input in the DOM. This ensures that screen reader users will land on a logical place when they navigate outside the dropdown. Unfortunately this is not possible with the date picker dropdown. It has to be inserted as a direct child of the body element so that it won't be clipped by ancestors. So, that leaves us with approach 1.

It is very tricky to design this widget for accessibility. The lowest common denominator are touch screen reader users since the main operations they can do are swipe to navigate to (not focus on) next element and double tap to activate them. Even if there are additional props to configure focus behavior, it may not be possible to predict what values to use.

tahoon-ms avatar Dec 24 '19 20:12 tahoon-ms

Verified on below test environment and found calendar window does not opened automatically when focus moves on ‘Select a date’.

Environment Details: URL: Home - Fluent UI (microsoft.com) OS Version: 21H2 (OS Build 22000.100) Edge Dev Version: Version 93.0.961.10 (Official build) dev (64-bit) Fabric Version: 8.26.2

opga11ytest avatar Aug 05 '21 05:08 opga11ytest

Because this reported issue has not had any activity for over 180 days, we're automatically closing it for house-keeping reasons.

Still require assistance? Please, create a new issue with up-to date details and latest version of Fluent.

msft-fluent-ui-bot avatar Feb 04 '22 17:02 msft-fluent-ui-bot