Skip to content

Add more menu selection customizability #1189

@adixon-adobe

Description

@adixon-adobe

This is a proposal to better support multiselect and un-selectable menu elements, and allow structured sub-handling in menu groups when necessary. It's modeled after the selects attribute already in sp-action-group. Creating this after a discussion with @Westbrook, and this is intended to consolidated/close issues #350 & #715

sp-action-menu supports new selects attribute

multiselect

With selects="multiple" any number of the items in the menu can be selected, and activating a menu item will toggle it's selected state.

<sp-action-menu selects="multiple">
	<sp-menu-item selected>item 1</sp-menu-item>
	<sp-menu-item>item 2</sp-menu-item>
	<sp-menu-item selected>item 3</sp-menu-item>
</sp-action-menu>

single

With selects="single" zero or 1 item can be selected.

<sp-action-menu selects="single">
	<sp-menu-item selected>item 1</sp-menu-item>
	<sp-menu-item>item 2</sp-menu-item>
	<sp-menu-item>item 3</sp-menu-item>
</sp-action-menu>

no selection (BREAKING CHANGE)

When the selects attribute is ommitted in sp-action-menu, items are not selectable. This better matches the general intent of action menu, where most items are actions that shouldn't be selected (e.g. File -> save... isn't an item you'd expect to be selected)

<sp-action-menu>
	<sp-menu-item>item 1</sp-menu-item>
	<sp-menu-item>item 2</sp-menu-item>
	<sp-menu-item>item 3</sp-menu-item>
</sp-action-menu>

sp-picker & sp-split-button are single-select

There is no selects attribute for these controls, as they're designed to have a single value selected.

sp-menu-group selects attribute

To allow for more granular selection handling, sp-menu-group also can provide a selects attribute, in which case it takes over managing selection for that sub menu. When present, the parent control is not notified of selection changes.

Example 1

This example shows an action menu that has both a multi-select and single-select group, along with an unselectable group. The sp-menu-group elements with the selects attribute present should fire a change event when their selection state changes, while the action menu would not as the handling is managed by the menu group.

<sp-action-menu>
	<sp-menu-group selects="multiple">
		<sp-menu-item selected>multiitem 1</sp-menu-item>
		<sp-menu-item>multiitem 2</sp-menu-item>
		<sp-menu-item selected>multiitem 3</sp-menu-item>
	</sp-menu-group>
	<sp-menu-group selects="single">
		<sp-menu-item selected>singleitem 1</sp-menu-item>
		<sp-menu-item>singleitem 2</sp-menu-item>
		<sp-menu-item>singleitem 3</sp-menu-item>
	</sp-menu-group>
	<sp-menu-group>
		<sp-menu-item>action 1</sp-menu-item>
		<sp-menu-item>action 2</sp-menu-item>
		<sp-menu-item>action 3</sp-menu-item>
	</sp-menu-group>
</sp-action-menu>

Example 2 (contrived case)

While this example is contrived, it helps illustrate the ownership & management. Since the overall action menu has selects="single", the unmanaged menu group for items 4 & 5 should be affected by that single select. Items 1-3 are managed by the multi-select menu group though. Clients should manage cases like this at the menu group level though.

<sp-action-menu selects="single">
	<sp-menu-group selects="multiple">
		<sp-menu-item>item 1</sp-menu-item>
		<sp-menu-item>item 2</sp-menu-item>
		<sp-menu-item>item 3</sp-menu-item>
	</sp-menu-group>
	<sp-menu-group>
		<sp-menu-item>item 4</sp-menu-item>
		<sp-menu-item>item 5</sp-menu-item>
	</sp-menu-group>
 </sp-action-menu>

### Core sp-menu change

To support the above examples, the `sp-menu` element will also add a `selects` attribute. Since these are now created/managed by `sp-action-menu`, `sp-picker`, & `sp-split-button` internally, they can just set the attribute properly for the component's context.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions