Skip to content

Conversation

@wh1teee
Copy link

@wh1teee wh1teee commented Sep 1, 2025

Autofocus: add support for delayed autofocus

Motivation

In some cases, setting focus too quickly (without a delay) sometimes broke the behavior of modal windows on mobile devices — the keyboard was rendered "on top" of the modal instead of pushing it up correctly.

Summary

  • Added support for delayed autofocus with autoFocus prop accepting boolean | number
  • Number value sets delay in milliseconds before focusing the first input
  • Maintains full backward compatibility with existing boolean behavior

Changes

  • Updated autoFocus type definition to boolean | number
  • Implemented setTimeout logic for delayed focus
  • Fixed refs stability issue with useMemo
  • Added tests for delayed autofocus functionality
  • Added Storybook examples demonstrating the feature

Test plan

  • All existing tests pass
  • New tests for delayed autofocus added
  • TypeScript compilation passes
  • ESLint checks pass
  • Manual testing in Storybook

- autoFocus prop now accepts boolean | number
- number value sets delay in milliseconds before focusing
- maintains backward compatibility with boolean values
@viclafouch
Copy link
Owner

Hello @wh1teee , do you have an example of this issue ?

@wh1teee
Copy link
Author

wh1teee commented Sep 8, 2025

Hello @wh1teee , do you have an example of this issue ?

Hello, @viclafouch!
I'm busy right now, I'll answer you within the next week or two

@darkdiesel
Copy link

@wh1teee ping )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants