Skip to content

Commit c9b6365

Browse files
committed
Prevent browser focus handling for labels and inputs in the canvas
A label with a mapping to an input causes the browser to autofocus the input. This isn't desirable when in the canvas because we're overriding selection behavior for elements. So, this turns it off with stopImmediatePropagation.
1 parent 1ebd79b commit c9b6365

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

.changeset/witty-lions-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compai/css-gui': patch
3+
---
4+
5+
Disable browser label/input selection handling in the canvas

apps/docs/data/initial-html-editor-data.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,4 +1634,46 @@ export const initialComponents: any = [
16341634
],
16351635
},
16361636
},
1637+
{
1638+
type: 'component',
1639+
id: 'ddeeff123',
1640+
tagName: 'Input',
1641+
attributes: {},
1642+
value: {
1643+
type: 'element',
1644+
tagName: 'input',
1645+
attributes: {},
1646+
style: {},
1647+
},
1648+
},
1649+
{
1650+
type: 'component',
1651+
id: 'ddeeff456',
1652+
tagName: 'Email Input',
1653+
attributes: {},
1654+
value: {
1655+
tagName: 'label',
1656+
attributes: {},
1657+
style: {},
1658+
children: [
1659+
{
1660+
type: 'element',
1661+
tagName: 'span',
1662+
attributes: {},
1663+
children: [{ type: 'text', value: 'Email' }],
1664+
},
1665+
{
1666+
type: 'component',
1667+
tagName: 'Input',
1668+
attributes: {},
1669+
value: {
1670+
type: 'element',
1671+
tagName: 'input',
1672+
attributes: {},
1673+
style: {},
1674+
},
1675+
},
1676+
],
1677+
},
1678+
},
16371679
]

packages/gui/src/components/html/Component/Provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function ComponentProvider({
4343
} = useHtmlEditor()
4444
const selectComponent = (e: MouseEvent) => {
4545
setSelected(path)
46-
e.stopPropagation()
46+
e.stopImmediatePropagation()
4747
}
4848

4949
const updateComponent = (fullEditPath: ElementPath, newValue: HtmlNode) => {

0 commit comments

Comments
 (0)