Skip to content

Commit 582bb93

Browse files
committed
selection mixing is selective about targets when selectable target is not changed
1 parent a108472 commit 582bb93

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/uui-base/lib/mixins/SelectableMixin.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,26 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(
115115

116116
if (isSelectable === false) return;
117117

118-
if (e.composedPath().indexOf(this.#selectableTarget) !== -1) {
118+
const composePath = e.composedPath();
119+
120+
if (this.#selectableTarget === this) {
121+
// the selectableTarget is not specified which means we need to be selective about what we accept events from.
122+
const isActionTag = composePath.some(el => {
123+
const elementTagName = (el as HTMLElement).tagName;
124+
return (
125+
elementTagName === 'A' ||
126+
elementTagName === 'BUTTON' ||
127+
elementTagName === 'INPUT' ||
128+
elementTagName === 'TEXTAREA' ||
129+
elementTagName === 'SELECT'
130+
);
131+
});
132+
133+
// never select when clicking on a link or button
134+
if (isActionTag) return;
135+
}
136+
137+
if (composePath.indexOf(this.#selectableTarget) !== -1) {
119138
if (e.type === 'keydown') {
120139
e.preventDefault(); // Do not want the space key to trigger a page scroll.
121140
}

0 commit comments

Comments
 (0)