UNPKG

4.76 kBMarkdownView Raw
1# Trailing Action (deprecated)
2
3The trailing action is used in removable input chips. It is a subcomponent of the chips and intended only for use in the context of a chip.
4
5## Basic Usage
6
7### HTML Structure
8
9```html
10<button class="mdc-deprecated-chip-trailing-action"
11 aria-label="Remove chip"
12 tabindex="-1">
13 <span class="mdc-deprecated-chip-trailing-action__ripple"></span>
14 <span class="mdc-deprecated-chip-trailing-action__icon material-icons">close</span>
15</button>
16```
17
18### Styles
19
20```scss
21@use "@material/chips/mdc-deprecated-chip-trailing-action";
22```
23
24## Variants
25
26### Non-navigable trailing action
27
28In some cases, the trailing action should be non-navigable. To accomplish this, swap the `aria-label` for `aria-hidden="true"`.
29
30```html
31<button class="mdc-deprecated-chip-trailing-action"
32 aria-hidden="true"
33 tabindex="-1">
34 <span class="mdc-deprecated-chip-trailing-action__icon material-icons">close</span>
35</button>
36```
37
38### Accessibility
39
40Material Design spec advises that touch targets should be at least 48 x 48 px.
41To meet this requirement, add the following to your trailing action:
42
43```html
44<button class="mdc-deprecated-chip-trailing-action"
45 aria-label="Remove chip"
46 tabindex="-1">
47 <span class="mdc-deprecated-chip-trailing-action__ripple"></span>
48 <span class="mdc-deprecated-chip-trailing-action__touch"></span>
49 <span class="mdc-deprecated-chip-trailing-action__icon material-icons">close</span>
50</button>
51```
52
53## Style Customization
54
55### CSS Classes
56
57CSS Class | Description
58--- | ---
59`mdc-deprecated-chip-trailing-action` | Mandatory.
60`mdc-deprecated-chip-trailing-action__icon` | Mandatory. Indicates the chip icon.
61`mdc-deprecated-chip-trailing-action__ripple` | Mandatory. Indicates the chip ripple.
62`mdc-deprecated-chip-trailing-action__touch` | Optional. Renders an accessible touch target.
63
64### Sass Mixins
65
66Mixin | Description
67--- | ---
68`color($color)` | Sets the trailing action color
69`size($size)` | Sets the trailing action size
70`horizontal-spacing($left, $right)` | Sets the trailing action horizontal spacing
71`touch-target-width($width)` | Sets the trailing action touch target width
72
73
74## `MDCChipTrailingAction` Methods
75
76Method Signature | Description
77--- | ---
78`removeFocus() => void` | Proxies to the foundation's `removeFocus` method
79`focus() => void` | Proxies to the foundation's `focus` method
80`isNavigable() => void` | Proxies to the foundation's `isNavigable` method
81
82##### Events
83
84Event Name | `event.detail` | Description
85--- | --- | ---
86`MDCChipTrailingAction:interaction` | `{trigger: InteractionTrigger}` | Indicates the trailing action was interacted with via mouse or keyboard
87`MDCChipTrailingAction:navigation` | `{key: string}` | Indicates a navigation event has occurred on a trailing action
88
89> _NOTE_: All of `MDCChipTrailingAction`'s emitted events bubble up through the DOM.
90
91## Usage within Web Frameworks
92
93If you are using a JavaScript framework, such as React or Angular, you can create Chips for your framework. Depending on your needs, you can use the _Simple Approach: Wrapping MDC Web Vanilla Components_, or the _Advanced Approach: Using Foundations and Adapters_. Please follow the instructions [here](../../docs/integrating-into-frameworks.md).
94
95### `MDCChipTrailingActionAdapter`
96
97See [`component.ts`](component.ts) for a vanilla DOM implementations of the adapter API for reference.
98
99Method Signature | Description
100--- | ---
101`focus() => void` | Gives focus to the root element
102`getAttribute(attr: string) => string|null` | Returns the attribute value, if present
103`notifyInteraction(trigger: InteractionTrigger) => void` | Notifies the Chip that the trailing action has been interacted with
104`notifyNavigation(key: string) => void` | Notifies the Chip that the trailing action was navigated
105`setAttribute(attr: string, value: string) => void` | Sets an attribute on the root to the given value
106
107### `MDCChipTrailingActionFoundation`
108
109Method Signature | Description
110--- | ---
111`removeFocus() => void` | Removes focus from the trailing action
112`focus() => void` | Gives focus to the trailing action
113`isNavigable() => boolean` | Returns the navigability of the trailing action
114`handleClick(evt: MouseEvent) => void` | Handles a click event on the root element
115`handleKeydown(evt: KeyboardEvent) => void` | Handles a keydown event on the root element
116
117#### `MDCChipTrailingActionFoundation` Event Handlers
118
119When wrapping the trailing action foundation, the following events must be bound to the indicated foundation methods:
120
121Events | Element Selector | Foundation Handler
122--- | --- | ---
123`click` | `.mdc-deprecated-chip-trailing-action` (root) | `handleClick()`
124`keydown` | `.mdc-deprecated-chip-trailing-action` (root) | `handleKeydown()`