Fix className.includes bug (#3672)

This PR (should) fix a Sentry bug:
https://tldraw.sentry.io/share/issue/c4cda01be5d142b79136e8ae97a7a3a7/

### Change Type

- [x] `sdk` — Changes the tldraw SDK
- [x] `bugfix` — Bug fix

### Release Notes

- Fixes a rare bug effecting text shapes on mobile.
This commit is contained in:
Steve Ruiz 2024-05-01 11:43:27 +01:00 committed by GitHub
parent 06be91b97b
commit 9ba4f7cf2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -105,17 +105,17 @@ export function useCanvasEvents() {
function onTouchEnd(e: React.TouchEvent) {
;(e as any).isKilled = true
// check that e.target is an HTMLElement
if (!(e.target instanceof HTMLElement)) return
if (
(e.target as HTMLElement).tagName !== 'A' &&
(e.target as HTMLElement).tagName !== 'TEXTAREA' &&
e.target.tagName !== 'A' &&
e.target.tagName !== 'TEXTAREA' &&
// When in EditingShape state, we are actually clicking on a 'DIV'
// not A/TEXTAREA element yet. So, to preserve cursor position
// for edit mode on mobile we need to not preventDefault.
// TODO: Find out if we still need this preventDefault in general though.
!(
editor.getEditingShape() &&
(e.target as HTMLElement).className.includes('tl-text-content')
)
!(editor.getEditingShape() && e.target.className.includes('tl-text-content'))
) {
preventDefault(e)
}