Cannot focus an input right after enabling it
I maintainer di solito rispondono entro 1 giorno
@alicewriteswrongs ci sta già lavorando.
Dal 27/10/2022.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Stencil version:
@stencil/[email protected]
Current behavior:
We have a wrapper around an HTML <input> , essentially this (most of the implementation elided for brevity):
export class WrapperTextInput {
@Prop({ mutable: true }) value: string;
@Prop() readonly disabled: boolean = false;
render() {
return (
<Host role="textbox" contenteditable="true">
<div>
<input type="text" value={this.value} disabled={this.disabled}></input>
</div>
</Host>
);
}
Now let's say the WrapperTextInput is disabled, and you run the following code:
wrapperTextInput.disabled= false;
wrapperTextInput.focus();
The call to focus() does not work. The component does not receive focus.
The following is a workaround:
wrapperTextInput.disabled= false;
setTimeout(() => wrapperTextInput.focus(), 50);
This is surprising to users of our components, considering a native <input> handles this without the need for a delay. This is even more awkward in React, as users expect a change in properties to be reflected in the DOM by the time the next useEffect runs, for instance.
I assume this workaround works because it gives the component time to render in its non-disabled state so it can be focused. Does this analysis make sense?
Expected behavior:
It should be possible to focus the component right after setting the disabled property to true.
Repro steps:
Repro here: https://github.com/asik/stencil-focus-issue-repro
You'll be able to see that the native input receives focus, but not the one wrapped in a stencil component.

(Clicked the Toggle native button, focus is given to the native input)

(Clicked the Toggle Stencil button, focus is not given to the stencil component.)
Other information:
Somewhat related https://github.com/ionic-team/stencil/issues/3246 - although here, it's about the user of a StencilJS component, using it as a black box, so they could not leverage its lifecycle methods like componentDidRender.
- Lingua principale
- TypeScript
- Stelle
- 13.2k
- Fork
- 865
- Merge medio
- 2g 16h
- PR unite (30g)
- 29
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di stenciljs/core
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug(mock-doc): `Element.toggleAttribute()` is missing, so components that use it fail during SSRApertatriage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Stencil FOUC styles should use @layer to avoid cascade conflicts with React 19Forse già presa @johnjenkins l’ha presa 230 giorni fa. ApertaStencil v5
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
stenciljs/core#7016 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di stenciljs/core
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
AykutSarac/jsoncrack.com#616 ·
-
nip27: long hashtag swallows the rest of the content, lone # gives an empty hashtagForse già presa @bardrop l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
nbd-wtf/nostr-tools#578 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
backnotprop/plannotator#3427 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
microsoft/Power-CAT-Copilot-Studio-Kit#942 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG]: Duplicate preposition in heading and unformatted feedback text on Strengthen Argument pageApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
AOSSIE-Org/DebateAI#801 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno