Skip to content

Commit

Permalink
feat(action-menu): remove menu selection by default
Browse files Browse the repository at this point in the history
Use the `selects` attribute set to `single` for previous functionality.
  • Loading branch information
Westbrook committed Jul 29, 2021
1 parent 6f21bef commit 54d636f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/action-menu/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Description

An `<sp-action-menu>` is an action button with a Popover. Use an `<sp-menu>` element to outline the items that will be made available to the user when interacting with the `sp-action-menu` element.
An `<sp-action-menu>` is an action button that triggers an overlay with `<sp-menu-items>` for activation. Use an `<sp-menu>` element to outline the items that will be made available to the user when interacting with the `<sp-action-menu>` element. By default `<sp-action-menu>` does not manage a selection. If you'd like for a selection to be held by the `<sp-menu>` that is presented in its overlay, use `selects="single"` to activate this functionality.

### Usage

Expand Down Expand Up @@ -219,6 +219,29 @@ A custom icon can be supplied via the `icon` slot in order to replace the defaul
</sp-action-menu>
```

### Selection.

When `selects` is set to `single`, the `<sp-action-menu>` element will maintain one selected item after an initial selection is made.

```html
<p>
The value of the `&lt;sp-action-menu&gt;` element is:
<span id="single-value"></span>
</p>
<sp-action-menu
selects="single"
onchange="this.previousElementSibling.querySelector('#single-value').textContent=this.value"
>
<span slot="label">Available shapes</span>
<sp-menu-item value="shape-1-square">Square</sp-menu-item>
<sp-menu-item value="shape-2-triangle">Triangle</sp-menu-item>
<sp-menu-item value="shape-3-parallelogram">Parallelogram</sp-menu-item>
<sp-menu-item value="shape-4-star">Star</sp-menu-item>
<sp-menu-item value="shape-5-hexagon">Hexagon</sp-menu-item>
<sp-menu-item value="shape-6-circle" disabled>Circle</sp-menu-item>
</sp-action-menu>
```

## Accessibility

An `<sp-action-menu>` parent will ensure that the internal `<sp-menu>` features a role of `listbox` and contains children with the role `option`. Upon focusing the `<sp-action-menu>` using `ArrowDown` will also open the menu while throwing focus into first selected (or unselected when none are selected) menu item to assist in selecting of a new value.
3 changes: 3 additions & 0 deletions packages/action-menu/src/ActionMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import actionMenuStyles from './action-menu.css.js';
* @element sp-action-menu
* @slot icon - The icon to use for action button
* @slot label - The label to use on for the action button
* @attr selects - By default `sp-action-menu` does not manage a selection. If
* you'd like for a selection to be held by the `sp-menu` that it presents in
* its overlay, use `selects="single" to activate this functionality.
*/
export class ActionMenu extends ObserveSlotText(PickerBase, 'label') {
public static get styles(): CSSResultArray {
Expand Down

0 comments on commit 54d636f

Please sign in to comment.