Semantic-UI-React icon indicating copy to clipboard operation
Semantic-UI-React copied to clipboard

Popup with input field's auto Focus not work as expected

Open ramyamahi opened this issue 6 years ago • 4 comments

Bug Report

Steps

I created a popup with the input field's autoFocus. click and open the popup with the input field.

Expected Result

At the time of popup open, it shouldn't scroll to the top of the page.

Actual Result

At the time of popup open, it will scroll to the top of the page.

Testcase

https://codesandbox.io/s/semantic-ui-example-xuich

ramyamahi avatar Dec 05 '19 11:12 ramyamahi

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

welcome[bot] avatar Dec 05 '19 11:12 welcome[bot]

This is an interesting edge case. Only happens due to the popup being rendered in a portal. And only happens when using autofocus. Triaging to needs engineering.

brianespinosa avatar Jul 28 '20 20:07 brianespinosa

Is there any update or a work around for this issue please?

mchountasis avatar Aug 23 '22 15:08 mchountasis

I faced the same problem.

As a workaround, I used the preventScroll option for the focus method, but an options parameter is not passed to the referenced input (PR with the fix: https://github.com/Semantic-Org/Semantic-UI-React/pull/4398).

So I created an extended Input component with an overridden focus method:

import { Input as SemanticUIInput } from 'semantic-ui-react';

export default class Input extends SemanticUIInput {
  focus = (options) => this.inputRef.current.focus(options);
}

Then I called the focus method manually in useEffect:

useEffect(() => {
  inputRef.current.focus({
    preventScroll: true
  });
}, []);

Updated testcase: https://codesandbox.io/s/semantic-ui-example-forked-fwx6pt?file=/example.js

meltyshev avatar Nov 11 '22 14:11 meltyshev