Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

[RFC] SplitButton component #1745

@silviuaavram

Description

@silviuaavram

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:

  1. Main button which, on trigger, executes the first option, the most used.
  2. Toggle button which, on toggle, shows/hides a menu with all the options.
  3. 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?: boolean

The 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:

PrimeReact:

  • 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.

Docsite Examples

  • Outlook New Message button, with both content and icons.
    Screenshot 2019-07-31 at 9 18 37 AM
  • Squash and merge similar button. Only content. Selection option just adds it to the button, so the user can click it afterwards (similar to how the Github button works).

Screenshot 2019-08-01 at 2 56 18 PM

- Main option disabled (and the main button implicitly) so user needs to go to the menu in order to perform an action, different from the main one.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions