textfields: wait a tick before selecting all to fix iOS (#3501)

fixes https://github.com/tldraw/tldraw/issues/3500

### Change Type

<!--  Please select a 'Scope' label ️ -->

- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff

<!--  Please select a 'Type' label ️ -->

- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
This commit is contained in:
Mime Čuvalo 2024-04-16 17:15:13 +01:00 committed by GitHub
parent fa3464ca8c
commit 7104515c9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,15 +39,18 @@ export function useEditableText(
useEffect(() => {
function selectAllIfEditing({ shapeId }: { shapeId: TLShapeId }) {
if (shapeId === id) {
const elm = rInput.current
if (elm) {
if (document.activeElement !== elm) {
elm.focus()
// We wait a tick, because on iOS, the keyboard will not show if we focus immediately.
requestAnimationFrame(() => {
if (shapeId === id) {
const elm = rInput.current
if (elm) {
if (document.activeElement !== elm) {
elm.focus()
}
elm.select()
}
elm.select()
}
}
})
}
editor.on('select-all-text', selectAllIfEditing)
return () => {