fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

[Bug]: DatePicker Compat steals focus on every render

Open ParadimeWeb opened this issue 3 years ago • 6 comments

Environment Information

Describe the issue:

Actual behavior:

When you have controlled components that re-renders the app, the datepicker steals the focus. Its probably has a bad useEffect code that focuses the component every time it renders.

A simple controlled Input component will have its focus stolen when typing a character in the input.

Expected behavior:

The DatePicker should not steal the focus on every render.

If applicable, please provide a codepen repro:

Simple codepen example of the bug:

Type into input which causes a re-render, and focus moves out of input to date picker.

https://codesandbox.io/s/sad-wright-t2hby7?file=/example.tsx:617-627

Priorities and help requested (not applicable if asking question):

Are you willing to submit a PR to fix? Yes

Requested priority: Blocking

Products/sites affected:

ParadimeWeb avatar May 26 '23 00:05 ParadimeWeb

https://github.com/microsoft/fluentui/blob/c29489c82d4e9dc541135e65f1e2a4a5159a2a05/packages/react-components/react-datepicker-compat/src/components/DatePicker/useDatePicker.tsx#LL29C10-L29C23

The function useFocusLogic returns a focus function that changes every time the component renders.

https://github.com/microsoft/fluentui/blob/c29489c82d4e9dc541135e65f1e2a4a5159a2a05/packages/react-components/react-datepicker-compat/src/components/DatePicker/useDatePicker.tsx#L427

The focus function is used in the useEffect dependencies. This will make the code run at every render.

I don't think you need focus as a dependencies. If you remove it from the dependencies array it should work.

ParadimeWeb avatar May 26 '23 00:05 ParadimeWeb

Not sure why this is not being triaged. It's a breaking bug.

ParadimeWeb avatar May 30 '23 01:05 ParadimeWeb

We're just back from a long weekend. I'll triage and get the component author involved as soon as I can.

micahgodbolt avatar May 30 '23 18:05 micahgodbolt

@ParadimeWeb Thanks for reporting the bug and going in depth! this will be closed with the PR linked. Thanks!

sopranopillow avatar May 30 '23 19:05 sopranopillow

:tada:This issue was addressed in #28053, which has now been successfully released as @fluentui/[email protected].:tada:

Handy links:

msft-fluent-ui-bot avatar May 31 '23 07:05 msft-fluent-ui-bot

:tada:This issue was addressed in #28053, which has now been successfully released as @fluentui/[email protected].:tada:

Handy links:

msft-fluent-ui-bot avatar May 31 '23 07:05 msft-fluent-ui-bot