Skip to content

Commit

Permalink
fix(menu): allow menu-item to support arbitrary element as the submen…
Browse files Browse the repository at this point in the history
…u root (#4720)

* fix(menu): allow using non-menu-item element as submenu root

* chore(menu): fixed broken test

* chore(menu): added a custom root submenu example in storybook

* chore(menu): updated docs

---------

Co-authored-by: Rúben Carvalho <[email protected]>
  • Loading branch information
2 people authored and nikkimk committed Sep 13, 2024
1 parent cf16c3e commit 18dee11
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions packages/menu/menu-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,42 +127,6 @@ Content assigned to the `value` slot will be placed at the end of the `<sp-menu-
</sp-menu>
```

Note: While `sp-menu-item` can accommodate any custom content in the `submenu` slot, it will not handle selection or keyboard navigation for such content. To ensure proper management of selection and keyboard navigation, it is recommended to use `sp-menu` within the `submenu` slot```

```html
<sp-menu style="width: 200px;">
<sp-menu-item>
Item with arbitrary content in submenu
<div role="menuitem" slot="submenu" style="padding: 12px">
<img
src="https://placekitten.com/200/200"
alt="Kitten"
style="width: 100%; height: auto; border-radius: 4px"
/>
<p>I am an arbitrary content in submenu</p>
</div>
</sp-menu-item>
</sp-menu>
```

Note: While `sp-menu-item` can accommodate any custom content in the `submenu` slot, it will not handle selection or keyboard navigation for such content. To ensure proper management of selection and keyboard navigation, it is recommended to use `sp-menu` within the `submenu` slot```

```html
<sp-menu style="width: 200px;">
<sp-menu-item>
Item with arbitrary content in submenu
<div role="menuitem" slot="submenu" style="padding: 12px">
<img
src="https://placekitten.com/200/200"
alt="Kitten"
style="width: 100%; height: auto; border-radius: 4px"
/>
<p>I am an arbitrary content in submenu</p>
</div>
</sp-menu-item>
</sp-menu>
```

#### Value attribute

When displayed as a descendent of an element that manages selection (e.g. `<sp-action-menu>`, `<sp-picker>`, `<sp-split-button>`, etc.), an `<sp-menu-item>` will represent the "selected" value of that ancestor when its `value` attribute or the trimmed `textContent` (represeted by `el.itemText`) matches the `value` of the ancestor element.
Expand Down Expand Up @@ -278,6 +242,24 @@ Note: While `sp-menu-item` can accommodate any custom content in the `submenu` s
</sp-menu>
```

Note: While `sp-menu-item` can accommodate any custom content in the `submenu` slot, it will not handle selection or keyboard navigation for such content. To ensure proper management of selection and keyboard navigation, it is recommended to use `sp-menu` within the `submenu` slot```

```html
<sp-menu style="width: 200px;">
<sp-menu-item>
Item with arbitrary content in submenu
<div role="menuitem" slot="submenu" style="padding: 12px">
<img
src="https://placekitten.com/200/200"
alt="Kitten"
style="width: 100%; height: auto; border-radius: 4px"
/>
<p>I am an arbitrary content in submenu</p>
</div>
</sp-menu-item>
</sp-menu>
```

### Accessibility guidelines

Review the guidelines for the parent [menu](../menu#accessibility-guidelines) and [menu-group](../menu-group#accessibility-guidelines).
Expand Down

0 comments on commit 18dee11

Please sign in to comment.