Support autoFocus
attribute in React-wrapped components
#381
Labels
enhancement
New feature or request
autoFocus
attribute in React-wrapped components
#381
Feature request
When using react component bindings, the
autofocus
/autoFocus
prop does not work on<VSCodeTextArea>
and<VSCodeTextField>
.Expected behavior
React components
<VSCodeTextArea>
and<VSCodeTextField>
should accept anautoFocus
prop which causes the components to focus when mounted.Current behavior
Note: React polyfills the autoFocus attribute on normal input elements so that they can be consistent and work with mounting component beyond just the first page load. It appears this polyfill does not happen when using with
VSCodeTextArea
andVSCodeTextField
.You can provide
autofocus
without a typescript warning, and it will addautofocus
to the innermost<textarea>
of the<vscode-text-area>
. However, this doesn't have the intended effect: the text area is not focused when added to the DOM (because the HTML attribute only applies on first page load in most browsers).It's possible to work around this issue by re-implementing this behavior using react hooks, however it's quite annoying to do so. (This is a separate issue but
ref
s are difficult to use with this library because of the types of components—you have to do an ugly type cast to make it work)Use case
It's very common to auto-focus text areas and text fields in forms that you want people to fill out. This is a common react idiom, so not having this makes the textarea/textfield components feel like weird bespoke components instead of acting like textareas and textfields that we're used to using.
Screenshots/references
To test this in an isolated environment, I added a
<VSCodeTextArea autofocus>Text Area!</VSCodeTextArea>
to the vscode-webview-ui-toolkit sample create-react-app project.When you launch the webview, it does not auto-focus the text area.
The text was updated successfully, but these errors were encountered: