Skip to content

Commit 94e8210

Browse files
committed
Merge branch 'v1/bugfix/selectableMixin-only-be-selective-when-selectabletarget-is-this' of https://github.com/umbraco/Umbraco.UI into v1/bugfix/selectableMixin-only-be-selective-when-selectabletarget-is-this
2 parents 209fbaf + d61f99a commit 94e8210

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
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
}

packages/uui-card-media/lib/uui-card-media.element.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ export class UUICardMediaElement extends UUICardElement {
9494
ifDefined(
9595
this.target === '_blank' ? 'noopener noreferrer' : undefined,
9696
),
97-
)}
98-
@click=${(e: MouseEvent) => e.stopPropagation()}>
97+
)}>
9998
${this.#renderContent()}
10099
</a>
101100
`;
@@ -121,9 +120,7 @@ export class UUICardMediaElement extends UUICardElement {
121120
<div id="select-border"></div>
122121
123122
<slot name="tag"></slot>
124-
<slot
125-
name="actions"
126-
@click=${(e: MouseEvent) => e.stopPropagation()}></slot>`;
123+
<slot name="actions"></slot>`;
127124
}
128125

129126
static styles = [

packages/uui-ref-node/lib/uui-ref-node.story.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const meta: Meta = {
1616
args: {
1717
name: 'Rabbit Suit Product Page',
1818
detail: 'path/to/nowhere',
19-
href: 'umbraco.com',
2019
},
2120
render: args =>
2221
html`<uui-ref-node ${spread(args)}>${renderSlots(args)}</uui-ref-node>`,
@@ -56,6 +55,13 @@ export const Standalone: Story = {
5655
},
5756
};
5857

58+
export const Href: Story = {
59+
args: {
60+
href: 'https://umbraco.com',
61+
target: '_blank',
62+
},
63+
};
64+
5965
export const Selectable: Story = {
6066
args: {
6167
selectable: true,

packages/uui-table/lib/uui-table-row.element.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
66
import { css, html, LitElement } from 'lit';
77
import { queryAssignedElements } from 'lit/decorators.js';
88

9-
import { UUITableCellElement } from './uui-table-cell.element';
10-
119
/**
1210
* Table row element with option to set is as selectable. Parent for uui-table-cell. Must be a child of uui-table.
1311
* @element uui-table-row
@@ -50,13 +48,15 @@ export class UUITableRowElement extends SelectOnlyMixin(
5048
private slotCellNodes?: unknown[];
5149

5250
protected updated(changedProperties: Map<string | number | symbol, unknown>) {
53-
if (changedProperties.has('selectOnly')) this.updateChildSelectOnly();
51+
if (changedProperties.has('selectOnly')) {
52+
this.updateChildSelectOnly();
53+
}
5454
}
5555

5656
private updateChildSelectOnly() {
5757
if (this.slotCellNodes) {
58-
this.slotCellNodes.forEach(el => {
59-
if (el instanceof UUITableCellElement) {
58+
this.slotCellNodes.forEach((el: any) => {
59+
if (el.disableChildInteraction !== undefined) {
6060
el.disableChildInteraction = this.selectOnly;
6161
}
6262
});

packages/uui-table/lib/uui-table-row.story.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { html } from 'lit';
44
import type { Meta, StoryObj } from '@storybook/web-components';
55
import { ArrayOfUmbracoWords } from '../../../storyhelpers/UmbracoWordGenerator';
66

7+
import '@umbraco-ui/uui-table';
8+
import '@umbraco-ui/uui-input';
9+
import '@umbraco-ui/uui-button';
10+
711
const meta: Meta = {
812
id: 'uui-table-row',
913
component: 'uui-table-row',
@@ -12,18 +16,24 @@ const meta: Meta = {
1216
<uui-table>
1317
<uui-table-row
1418
?selectable=${args.selectable}
15-
?selectOnly=${args.selectOnly}>
19+
?select-only=${args.selectOnly}>
1620
${ArrayOfUmbracoWords(5).map(
1721
el => html`<uui-table-cell>${el}</uui-table-cell>`,
1822
)}
1923
</uui-table-row>
2024
<uui-table-row
2125
?selectable=${args.selectable}
22-
?selectOnly=${args.selectOnly}>
26+
?select-only=${args.selectOnly}>
2327
<uui-table-cell>
2428
<uui-input placeholder="Type your own thing"></uui-input>
2529
</uui-table-cell>
26-
${ArrayOfUmbracoWords(5).map(
30+
<uui-table-cell>
31+
<uui-button label="some button"></uui-button>
32+
</uui-table-cell>
33+
<uui-table-cell>
34+
<a href="http://www.umbraco.com" target="_blank">Link</a>
35+
</uui-table-cell>
36+
${ArrayOfUmbracoWords(3).map(
2737
el => html`<uui-table-cell>${el}</uui-table-cell>`,
2838
)}
2939
</uui-table-row>

0 commit comments

Comments
 (0)