Skip to content
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

Method of programmatically applying focus to text field in react #512

Open
tomqwpl opened this issue Oct 17, 2023 · 2 comments
Open

Method of programmatically applying focus to text field in react #512

tomqwpl opened this issue Oct 17, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@tomqwpl
Copy link

tomqwpl commented Oct 17, 2023

Feature request

I suspect I'm being a bit dim here as this seems such an obvious requirement. There doesn't seem to be any method of programmatically applying focus to a text field when using React and vscode-webview-ui-toolkit. The components generally don't seem to support react "refs", so I can't get a ref to the underlying component, and there seems to be no other method that I can find.

Expected behavior

Either support "ref" on VSCodeTextField and forward it down to the tag, or support focus() method on the VSCodeTextField and have that apply focus to the relevant tag.

Current behavior

No apparent way to control focus at all that I can find.

Use case

For example, look at the VSCode settings editor. The "Unicode Highlighting: Allowed Characters" table for example:
image

When you press "Add Item" it creates two entry fields and puts focus in one of them.
There's no apparent way of implementing something like that using this toolkit and react that I can find. So I don't appear to be able to implement something using this toolkit in a webview that follows the look and feel and behaviour exhibited by standard parts of VSCode.

Screenshots/references

@tomqwpl tomqwpl added the enhancement New feature or request label Oct 17, 2023
@snoop244
Copy link

It would be great to see this enhancement as I'm also looking to set focus programmatically.

@sketchbuch
Copy link

sketchbuch commented Apr 28, 2024

In my webview, I can set focus on an input just by calling focus(). Maybe as it is not working using refs, you could just get the field by id and focus it as a work around for now. This is basically what I do as I'm just using string literals for templating rather than using something like react.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants