Skip to content

Update internal item and list-box elements to use mixins instead of extending #5358

Closed

Description

@web-padawan

Motivation

Currently, we have the following set of item components and their extensions in our codebase:

Item elements

vaadin-item

class Item extends ItemMixin(ThemableMixin(DirMixin(PolymerElement))) {

class ContextMenuItem extends Item {

class SelectItem extends Item {

We also plan to add vaadin-menu-bar-item in Vaadin 24 - see #3010 and #5339 (currently in review).

vaadin-combo-box-item

export class ComboBoxItem extends ThemableMixin(DirMixin(PolymerElement)) {

class TimePickerItem extends ComboBoxItem {

class MultiSelectComboBoxItem extends ComboBoxItem {

ListBox elements

class ListBox extends ElementMixin(MultiSelectListMixin(ThemableMixin(ControllerMixin(PolymerElement)))) {

class ContextMenuListBox extends ListBox {

class SelectListBox extends ListBox {

Problem

The main problem is that some components are currently leaking their implementation detail to the users:

  1. Importing vaadin-time-picker also defines vaadin-combo-box-item in the custom element registry,
  2. Styles that are applied to vaadin-item using registerStyles also apply to vaadin-select-item etc,
  3. In vaadin-list-box we use MultiSelectListMixin but we don't need that in vaadin-select-list-box.
  4. The fact that classes extend each other makes it more complicated to convert them to Lit in the future,

Proposed Solution

  1. Update all the item and list-box classes to avoid usage of extends,
  2. Share logic using mixins instead: create ComboBoxItemMixin etc,
  3. Share styles by exporting css tagged literals from theme JS files.

Alternatives

Keep extending ListBox and Item, also in new elements: vaadin-menu-bar-list-box and vaadin-menu-bar-item.

Note

There are a few other elements that could be also updated similarly:

  • vaadin-time-picker-scroller extends vaadin-combo-box-scroller
  • vaadin-time-picker-overlay extends vaadin-combo-box-overlay
  • vaadin-menu-bar-overlay extends vaadin-context-menu-overlay

Activity

  1. web-padawan commented on Jan 23, 2023

    @web-padawan
    MemberAuthor

    Conclusion from the daily: this change is quite similar to what we already did in Vaadin 22 with decoupling components that were based on vaadin-text-field to not use it internally. And hopefully, users don't style items that much as fields.

    Also, the same change was done in Vaadin 24 for vaadin-accordion-panel which no longer extends vaadin-details.
    We even had an issue reported about the confusion related to styles for these components - see #412.

    So, we want to fix this at least for item and list-box extensions for Vaadin 24, and I'll work to get it done this week.

  2. web-padawan commented on Jan 24, 2023

    @web-padawan
    MemberAuthor

    Item and List-box extensions

    • vaadin-avatar-group-item
    • vaadin-avatar-group-menu
    • vaadin-combo-box-item (mixin)
    • vaadin-context-menu-item
    • vaadin-context-menu-list-box
    • vaadin-menu-bar-item
    • vaadin-menu-bar-list-box
    • vaadin-multi-select-combo-box-item
    • vaadin-select-item
    • vaadin-select-list-box
    • vaadin-time-picker-item

    Overlay extensions

    • vaadin-menu-bar-overlay
    • vaadin-time-picker-overlay
    • vaadin-multi-select-combo-box-overlay

    Scroller extensions

    • vaadin-time-picker-scroller
    • vaadin-multi-select-combo-box-scroller
  3. web-padawan commented on Jan 27, 2023

    @web-padawan
    MemberAuthor

    Closing as completed, see individual PRs linked to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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