Skip to content

Commit

Permalink
media card selectable solution
Browse files Browse the repository at this point in the history
  • Loading branch information
nielslyngsoe committed Nov 26, 2024
1 parent ef1cbae commit 2adab35
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/uui-base/lib/mixins/SelectableMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export const SelectableMixin = <T extends Constructor<LitElement>>(

readonly #onKeydown = (e: KeyboardEvent) => {
if (e.code !== 'Space' && e.code !== 'Enter') return;
this.#onClick(e);
if (e.composedPath().indexOf(this.#selectableTarget) === 0) {
this.#onClick(e);
}
};

readonly #onClick = (e: Event) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/uui-card-media/lib/uui-card-media.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export class UUICardMediaElement extends UUICardElement {
ifDefined(
this.target === '_blank' ? 'noopener noreferrer' : undefined,
),
)}>
)}
@click=${(e: MouseEvent) => e.stopPropagation()}>
${this.#renderContent()}
</a>
`;
Expand All @@ -120,7 +121,9 @@ export class UUICardMediaElement extends UUICardElement {
<div id="select-border"></div>
<slot name="tag"></slot>
<slot name="actions"></slot>`;
<slot
name="actions"
@click=${(e: MouseEvent) => e.stopPropagation()}></slot>`;
}

static styles = [
Expand Down
14 changes: 14 additions & 0 deletions packages/uui-card-media/lib/uui-card-media.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ export const Actions: Story = {
},
};

export const Href: Story = {
args: {
'actions slot': html`<uui-button
slot="actions"
look="secondary"
label="Remove"
>Remove</uui-button
>`,
selectable: true,
href: 'https://umbraco.com',
target: '_blank',
},
};

export const Image: Story = {
args: {
slot: html`<img src="https://placedog.net/1447/?random" alt="" />`,
Expand Down

0 comments on commit 2adab35

Please sign in to comment.