Add new Splitbutton render element to eventually replace Dropbutton

Created on 25 January 2013, over 11 years ago
Updated 11 September 2023, 9 months ago

To evaluate splitbuttons from the MR, enable the splitbutton_test module and go to

/splitbuttons

. You must have

$settings['extension_discovery_scan_tests'] = TRUE;

in your settings.php for this test module to be available.

Problem

  1. Drupal has adopted Views’ dropbutton in several common places in core. Since its introduction in #1608878: Add CTools dropbutton to core , we've spent lots of time refactoring the existing button: #1799498: Improve dropbutton and others [which?]. This component is now even being used for primary form actions on the new node edit form: #1751606: Move published status checkbox next to "Save" . However, the implementation there has made the dropbutton harder to theme by pushing it beyond its initial design. (Specifically, allowing its to consist of buttons instead of links, and by introducing sub-elements using #prefix and #suffix).
  2. From a UX standpoint, the existing dropbutton’s behaviour is sub-optimal. Since the sub-items are contained within the button, when the button is opened it often must grow in width to accommodate the width of the sub-items. This change moves the click target out from under the user’s cursor, forcing them to hit a slightly different spot in order to close the menu again. In some cases, such as the one reported in #3168326: Dropbuttons in table cells are potentially unusable if it includes options with long text length. , opening the dropbutton can result in a reposition that takes the pointer off the dropbotton, which results in it being closed moments after it was opened. The standard implementation of this design pattern does not suffer from this issue: Twitter Bootstrap, Zurb Foundation, jQuery UI. Drupal is the odd one out here.
  3. The open/closed state of the menu isn't conveyed to assistive technology, it is only apparent visually.
  4. The current focus style for the more-actions button is weak, and won't pass WCAG 1.4.11 Non-text contrast.

Proposed Resolution

Since we cannot change the current Dropbutton (and Operations) implementation for BC reasons, the way to move on is:

  1. Create a new Splitbutton element with the required markup, functionality and (accessibility) features.

    • The new Splitbutton element must allow having buttons as well as links, and it should be able to replace the hard-coded fake Dropbutton in Views UI.
    • It should be easy to add modifier CSS classes (described in #2160481: Componentize the dropbutton CSS ).
    • Use aria-haspopup and aria-expanded to define the list and toggle to assistive tech.
    • Should have the proper focus styles, to satisfy WCAG success criteria 1.4.11 Non-text contrast. Using an outline (i.e. shape) change is recommended, rather than changing colour alone.
  2. Use the popover api for visiblity toggling
  3. Use the Floating UI library for positioning. Positioning will likely switch to use the anchor positioning API when browser support is better.
  4. In followup: Replace core's Dropbutton and Operations usage where appropriate with the new Splitbutton element.
  5. In a followup: Potentially deprecate Dropbutton. (?)

User interface changes

Splitbutton is a slightly different experience than dropbutton. Dropbutton has a primary item that is always visible. Although it's a primary item, it's semantically part of the the list that is fully visible when the dropbutton is open.
Seven no longer in core

Claro Dropbutton
Claro is styled so the primary and list items look different although they are part of the same list. This visually resembles what splitbutton will be doing semantically.

Seven no longer in core

Claro Splitbutton
Uses Claro's existing component styles, applied to this new element.

Dependency Evaluation

The Popover API is pretty close to being adopted in all Drupal supported browsers, but at the moment still needs a polyfill. There appears to be only one easily found option - https://github.com/oddbird/popover-polyfill. Going with the Popover API is highly preferable to adding this logic in core. It completely removes the need to decide on the proper z-index, and splitbutton CSS is only responsible for how it looks - not whether or not is it visible.

  1. Maintainership of the package: Issues appear to be responded to in a timely manner, and there is regular activity on the project. It looks like the maintainers use this in their own projects so I imaging there is incentive to continue for the likely-brief time it will take before native adoption renders this unnecessary
  2. Security Policies Nothing official that I could find, so I posted an issue requesting clarification https://github.com/oddbird/popover-polyfill/issues/110. The nature of the feature/polyfill does not introduce huge exploitation opportunities, but it would still be good to get some clarity on this.
  3. Expected release and support cycles This was asked in the same issue where I inquired about security info. This appears to release as-needed, which seems especially appropriate given the very-specific purpose of this polyfill and the fact that it will potentially be obsolete before Drupal 11 is even tagged.
  4. Code quality The job requirements of this polyfill are quite straightforward. The code is easy to read and largely self explanatory but there are decent comments where needed.CSS is used to manage visibility when there isn't a browser API isn't available to do it, and it does a good job of mimicking the native implementation specs.
  5. Dependencies added No runtime dependencies, dev dependencies are all popular build/lint/test tools + typescript.

API changes

TBD.

Original Proposed Resolution

Feature request
Status

Needs work

Version

11.0 🔥

Component
Theme 

Last updated 1 day ago

Created by

🇩🇪Germany sun Karlsruhe

Live updates comments and jobs are added and updated live.
  • API clean-up

    Refactors an existing API or subsystem for consistency, performance, modularization, flexibility, third-party integration, etc. May imply an API change. Frequently used during the Code Slush phase of the release cycle.

  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

  • Needs accessibility review

    Used to alert the accessibility topic maintainer(s) that an issue significantly affects (or has the potential to affect) the accessibility of Drupal, and their signoff is needed (see the governance policy draft for more information). Useful links: Drupal's accessibility standards, the Drupal Core accessibility gate.

  • Field UX

    Usability improvements related to the Field UI

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024