Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tag): keyboard support for dismiss button #533

Merged
merged 3 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/src/components/tag/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
| Part | Description |
| ---------------------- | ----------- |
| `"button-dismissable"` | |
| `"icon-dismissable"` | |


## Dependencies
Expand Down
7 changes: 2 additions & 5 deletions packages/components/src/components/tag/tag.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

--border-button-dismissable-focus: 1px solid
var(--scl-color-background-standard);
--background-button-dismissable-focus: var(--scl-color-black);
--background-button-dismissable-focus: ;
--box-shadow-button-dismissable-focus: var(--box-shadow-focus);
--background-button-dismissable-hover: var(--scl-color-black);
--background-button-dismissable-hover: ;
--height-button-dismissable-small: 20px;

--spacing-small: 0 var(--scl-spacing-8);
Expand Down Expand Up @@ -86,9 +86,6 @@
border-radius: var(--radius);
}

.tag--dismissable scale-icon-action-close svg {
outline: none;
}
.tag--dismissable button:focus {
border: var(--border-button-dismissable-focus);
background: var(--background-button-dismissable-focus);
Expand Down
14 changes: 6 additions & 8 deletions packages/components/src/components/tag/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ export class Tag {
componentWillUpdate() {}
disconnectedCallback() {}

handleClose(event) {
handleClose = (event: MouseEvent) => {
event.preventDefault();
event.stopPropagation();
if (this.disabled) {
return;
}
this.scaleClose.emit(event);
}
};

render() {
const Element = !!this.href && !this.disabled ? 'a' : 'span';
Expand All @@ -54,11 +57,6 @@ export class Tag {
target: this.target,
}
: {};
const iconProps = !this.disabled
? {
onClick: (event) => this.handleClose(event),
}
: {};

return (
<Host>
Expand All @@ -76,11 +74,11 @@ export class Tag {
part="button-dismissable"
disabled={this.disabled}
aria-label={this.dismissText}
onClick={this.handleClose}
>
<scale-icon-action-close
part="icon-dismissable"
size={this.size === 'small' ? 20 : 24}
{...iconProps}
/>
</button>
)}
Expand Down
25 changes: 0 additions & 25 deletions packages/storybook-vue/stories/3_components/tag/ScaleTag.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<template>
<scale-tag
:disabled="disabled"
:dismissable="dismissable"
:dismiss-text="dismissText"
:href="href"
:size="size"
:target="target"
:variant="variant"
@click="click"
@scaleClose="click"
:styles="styles"
>
<slot></slot>
</scale-tag>
</template>

<script>
import { action } from "@storybook/addon-actions";

export default {
props: {
disabled: { type: Boolean, default: false },
Expand All @@ -29,11 +10,5 @@ export default {
variant: String,
styles: String,
},
methods: {
click: function ($event) {
action("click");
this.$emit("click", $event);
},
},
};
</script>
22 changes: 13 additions & 9 deletions packages/storybook-vue/stories/3_components/tag/Tag.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Description,
} from "@storybook/addon-docs/blocks";
import ScaleTag from "./ScaleTag.vue";
import { action } from "@storybook/addon-actions";

<Meta
title="Components/Tag"
Expand All @@ -27,34 +28,35 @@ import ScaleTag from "./ScaleTag.vue";
/>

export const Template = (args, { argTypes }) => ({
components: { ScaleTag },
props: {
label: String,
...ScaleTag.props,
},
template: `
<scale-tag
:disabled="disabled"
:dismissable="dismissable"
:href="href"
:size="size"
:target="target"
:variant="variant"
:disabled="disabled"
:dismissable="dismissable"
:href="href"
:size="size"
:target="target"
:variant="variant"
@scaleClose="action('scaleClose')($event)"
>
{{ label }}
</scale-tag>
`,
methods: {
action
}
});

export const TemplateInteractive = (args, { argTypes }) => ({
components: { ScaleTag },
template: `
<ul aria-label="fruits" style="display: flex; list-style: none; padding: 0;">
<li v-for="fruit in fruits" :key="fruit" style="margin-right: 4px;">
<scale-tag
dismissable="true"
v-bind:dismiss-text="'Remove ' + fruit + ' from the list'"
@click="removeFruit(fruit)"
@scaleClose="removeFruit(fruit)"
>
{{fruit}}
Expand All @@ -63,7 +65,9 @@ export const TemplateInteractive = (args, { argTypes }) => ({
</ul>
`,
methods: {
action: action('scaleClose'),
removeFruit(fruit) {
this.action();
this.fruits = this.fruits.filter((x) => x !== fruit);
setTimeout(() => {
this.$el.querySelector("#root > ul > li > scale-tag") &&
Expand Down