Comments (3)
@Geordi7 It seems the first approach causes the entire parent div
to refresh, which wipes out the input
element, killing the focus. Wrapping it in a span
so it has its own node also seems to resolve the issue.
const focus = e => e.focus();
class C extends Component {
state = {a: {b: {c: ''}}}
view = s => <div>
<span>Hello {s.a.b.c}</span>
<input type='text' value={s.a.b.c}
$oninput={(s,e) => (s.a.b.c=e.target.value, s)}
/>
</div>
}
new C().start(document.body)
Another solution might be to use a ref
so it's refocused when the input
element is refreshed:
const focus = e => e.focus();
class C extends Component {
state = {a: {b: {c: ''}}}
view = s => <div>
Hello {s.a.b.c}<br/>
<input ref={focus} type='text' value={s.a.b.c}
$oninput={(s,e) => (s.a.b.c=e.target.value, s)}
/>
</div>
}
new C().start(document.body)
There's an example called Ref - Examples that uses the ref
approach for contenteditable also, which I've noticed can be quirky in frameworks also for similar reasons.
from apprun.
After further testing it seems the problem is not with the input itself but with the text node before it.
if you replace Hello {s.a.b.c}<br />
with {'Hello ' + s.a.b.c}<br />
it works correctly.
This is probably still a bug.
from apprun.
I ran into another good usage for ref
. MaterializeCSS relies on input
elements having a specific type set, but when type="text"
will sometimes get stripped from the element because it's the default, causing the label animations not to work. I was able to use a ref
to specifically reset the type
attribute which fixed the issue.
from apprun.
Related Issues (20)
- How to handle file drop? HOT 1
- Update URL in the browser's address bar when SPA component activates HOT 4
- How to avoid triggering components initial event handler on form submit? HOT 2
- Problem using input element with list attribute HOT 2
- No jest in default SPA HOT 1
- Broken Link in docs HOT 1
- Example of child component updating parent's state? HOT 2
- First page always blank in sample. HOT 1
- Components within HTML string view pattern HOT 4
- Discord link on the website is broken HOT 1
- Can I use other libraries in place of lit-html? HOT 7
- global values created for ESM version HOT 1
- Cannot GET / HOT 4
- How to put 'selected' on <option>? HOT 3
- lit-html code not working in the docs HOT 2
- Doubling components on the screen HOT 5
- Can't switch appRun components by switching in state HOT 2
- Is there a way to trigger event from console? HOT 3
- Snowpack template for AppRun? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apprun.