bug: calling `focus` on an input element inside `componentDidLoad` does not work
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- frontend
Research direction
Reproduce the issue using the input-with-focus.tsx and my-component.tsx examples from the report, then compare the behavior with related issue #1758. Trace the component lifecycle around componentDidLoad and the ref callback; done means the nested input receives focus after the page loads.
Written by the indexing model from the issue text.
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
2.14.0
Current Behavior
Calling focus on an input element inside componentDidLoad does not work.
Expected Behavior
The input should be focused after the page load.
Steps to Reproduce
npm init stencil- Pick
component - Pick
<projectname> cd <projectname>npm installnpm run generate- Pick
input-with-focus - Edit
input-with-focus.tsxto look like this:
import { Component, Host, h } from '@stencil/core';
@Component({
tag: 'input-with-focus',
styleUrl: 'input-with-focus.css',
shadow: true,
})
export class InputWithFocus {
inputElement: HTMLInputElement;
componentDidLoad() {
this.inputElement.focus();
}
render() {
return (
<Host>
<input ref={(el) => { this.inputElement = el; }} placeholder="I should be focused" />
</Host>
);
}
}
- Edit
my-component.tsxto look like this:
import { Component, h } from '@stencil/core';
@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: true,
})
export class MyComponent {
render() {
return (
<input-with-focus></input-with-focus>
);
}
}
npm start- Observe that the input is not focused
Code Reproduction URL
https://github.com/menelaos/stencil-focus-issue
Additional Information
Possibly related: https://github.com/ionic-team/stencil/issues/1758
- Dominant language
- TypeScript
- Stars
- 13.1k
- Forks
- 855
- Avg merge
- 4h 7m
- Merged PRs (30d)
- 44
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stenciljs/core
-
Stencil v5
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Bug: Validated Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Feature: Want this? Upvote it!
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Feature: Want this? Upvote it!
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·