-
Notifications
You must be signed in to change notification settings - Fork 51
[RFC] SplitButton component #1745
Description
Split Button component
Problem description
We need a component that offers the user a list of actionable options. The first option, most used, should be actionable by a button. All the options should be contained in a menu that is shown via a toggle action, provided by a second button.
Proposed solution
The SplitButton should be a widget containing:
- Main button which, on trigger, executes the first option, the most used.
- Toggle button which, on toggle, shows/hides a menu with all the options.
- Vertical Menu that contains the options. Clicking an option should trigger the action associated with that option. Optionally, it should just replace the active option on the main button which will be executed by click.
API Proposal
/** Shorthand array of props for Menu. */
items: ShorthandCollection<MenuItemProps>
/** Index of the item that appears on the button. Default is 0. */
mainItemIndex: number
/**
* Called after user's click.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All props.
*/
onClick?: ComponentEventHandler<ButtonProps>
/**
* Called when an item is clicked.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All item props.
*/
onItemClick?: ComponentEventHandler<MenuItemProps>
/**
* Called after user's click on the toggle button.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All item props.
*/
onToggle?: ComponentEventHandler<ButtonProps>
/** The toggle button to display menu of items. */
toggleButton?: ShorthandValue<ButtonProps>
/** A split button can be formatted to show different levels of emphasis. */
primary?: boolean
/** A split button can be formatted to show different levels of emphasis. */
secondary?: booleanThe items shorthand will be used to create both the Button and the MenuItem. Both have in common content and icon. Also onClick which is used to execute actions.
SplitButton will accept props such as primary and secondary which will be passed to both buttons. For further individual customisation, shorthands should be used.
If we decide to have shorthand for the main button as well, then we need to manually merge props between this shorthand and the item associated to it.
Other Libraries APIs:
- main option is completely separated from other options.
- items have similar shorthand props: label (content), icon, command (onClick).
Accessibility:
- select options via keyboard from the menu. Highlighted option should be maintained in state and keydown for up/down arrows should be added to toggleButton, via behaviors.
- narration of these options.
- expanded/collapsed on the toggle button.
Alternative
Create examples in the docsite that show how to use Button and Menu to create such a widget, without creating an actual component.
Stateful logic may not be trivial if we also want to add kb navigation between the items.

