Principes Bases Accessibilité Système de design Guidelines Deutsch Français Italiano English Nos principes de design Centré sur l’utilisateur Reconnaissable Inclusif Minimaliste Holistique Auto-explicatif Axé sur les tâches Approprié Portail de la marque CFF Logo Horloge numérique Droits d’utilisation Couleurs de base Couleurs supplémentaires Couleurs off-brand Icônes Icônes de l’horaire Pictogrammes À propos de l’accessibilité À propos de ce guide Contact Informations complémentaires Product Owner User Research Interaction Design Visual Design Development Content Design Testing What is a design system? Conception Développer FAQ Aide Procès Contribution Contact Aperçu Base Composants Aperçu Releases Design Tokens Composants Aperçu Base Informations Aperçu Base Composants Aperçu Power-Apps Bandeaux publicitaires numériques SAP IA Design : Bases Icônes d’applications Cette page n'est pas disponible dans la langue souhaitée. Langues disponibles: Deutsch English Autocomplete-Grid Info

Was macht die Komponente?

Die Komponente bietet die gleichen Funktionalitäten wie die Autocomplete-Komponente, bietet aber zusätzlich die Möglichkeit Buttons neben den Optionen darzustellen.

Wann soll die Komponente eingesetzt werden?

  • Nur wenn zu den abgebildeteten Optionen in der Autocomplete-Liste auch noch Button nötig sind.

Regeln

  • Die Komponente soll nicht bei kleinen Datensätzen (z.b. nur 10 Einträge/Optionen) verwendet werden.
  • Die Autocomplete-Liste soll nicht zu viele Vorschläge auf einmal anzeigen, um die Übersichtlichkeit zu bewahren (max. 10 Vorschläge).
  • Die Nutzenden sollen die Möglichkeit haben, die Autocomplete-Funktion zu ignorieren und eigene Eingaben zu machen.
Autocomplete-Grid Select Autocomplete-Grid-Button Autocomplete-Grid-Cell Autocomplete-Grid-Optgroup Autocomplete-Grid-Option Autocomplete-Grid-Row Option Optgroup Form-Field
Anatomie

Anatomie der Komponente


Nummer Typ Beschreibung Optional Hinweis
1 Komponente sbb-form-field Nein
1a Standard-HTML label Nein
1b Standard-HTML input Nein
1c Komponente sbb-icon Ja Prefix
1d Komponente sbb-icon Ja Suffix
2 Komponente sbb-autocomplete-grid-optgroup Ja
2a Text Label Nein
2b Komponente sbb-divider - Erscheint bei einer sbb-autocomplete-grid-optgroup
3 Komponente sbb-autocomplete-grid-row Nein
4 Komponente sbb-autocomplete-grid-option Nein
4a Text Value Nein
4b Komponente sbb-icon Ja
5 Komponente sbb-autocomplete-grid-cell Ja
6 Komponente sbb-autocomplete-grid-button Ja
Demo

Spielwiese

Option 1-1 Option 1-2 Option 1-3 Option 2-1 Option 2-2 Option 2-3
Label einrücken Nein Ja Grössen M S Negativ Nein Ja Mode (System-Einstellung) Light Dark Hintergrund White Midnight Milk Charcoal Cloud Iron Midnight White Charcoal Milk Iron Cloud
HTML in Zwischenablage kopiert.
Implementation

The sbb-autocomplete-grid is a component that can be used to display a panel of suggested options connected to a text input,
with each option connected to one or more buttons.
Use it when you need an autocomplete in which every selectable option in the panel needs one or more related button.
If you don't need actions, use the sbb-autocomplete.

The component is strictly connected to:

It's possible to set the element to which the component's panel will be attached using the origin prop,
and the input which will work as a trigger using the trigger prop.
Both accept an id or an element reference.

<!-- Origin element -->
<div id="autocomplete-origin">Another origin</div>

<!-- Trigger element -->
<input id="autocomplete-txt" placeholder="Another trigger element" />

<sbb-autocomplete-grid origin="autocomplete-origin" trigger="autocomplete-txt">
  <sbb-autocomplete-grid-row>
    <sbb-autocomplete-grid-option value="1">Option 1</sbb-autocomplete-grid-option>
    <sbb-autocomplete-grid-cell>
      <sbb-autocomplete-grid-button icon-name="pen-small"></sbb-autocomplete-grid-button>
    </sbb-autocomplete-grid-cell>
  </sbb-autocomplete-grid-row>
  <sbb-autocomplete-grid-row>
    <sbb-autocomplete-grid-option value="2">Option 2</sbb-autocomplete-grid-option>
    <sbb-autocomplete-grid-cell>
      <sbb-autocomplete-grid-button icon-name="trash-small"></sbb-autocomplete-grid-button>
    </sbb-autocomplete-grid-cell>
  </sbb-autocomplete-grid-row>
</sbb-autocomplete-grid>

In sbb-form-field

If the component is used within a sbb-form-field,
it will automatically connect to the native <input> as trigger and will display the option panel above or below the sbb-form-field.

<!-- Origin element -->
<sbb-form-field label="Label">
  <!-- Trigger element -->
  <input placeholder="Trigger element" />

  <sbb-autocomplete-grid>
    <sbb-autocomplete-grid-row>
      <sbb-autocomplete-grid-option value="1">Option 1</sbb-autocomplete-grid-option>
      <sbb-autocomplete-grid-cell>
        <sbb-autocomplete-grid-button icon-name="pen-small"></sbb-autocomplete-grid-button>
      </sbb-autocomplete-grid-cell>
    </sbb-autocomplete-grid-row>
    <sbb-autocomplete-grid-row>
      <sbb-autocomplete-grid-option value="2">Option 2</sbb-autocomplete-grid-option>
      <sbb-autocomplete-grid-cell>
        <sbb-autocomplete-grid-button icon-name="trash-small"></sbb-autocomplete-grid-button>
      </sbb-autocomplete-grid-cell>
    </sbb-autocomplete-grid-row>
  </sbb-autocomplete-grid>
</sbb-form-field>

Style

Option highlight

By default, the sbb-autocomplete-grid will highlight the label of the sbb-autocomplete-grid-option in the panel,
if it matches the typed text.
See the sbb-autocomplete-grid-option for more details.

Option grouping

The displayed sbb-autocomplete-grid-option can be collected into groups using sbb-autocomplete-grid-optgroup element:

<!-- Origin element -->
<sbb-form-field label="Label">
  <!-- Trigger element -->
  <input placeholder="Trigger element" />

  <sbb-autocomplete-grid>
    <sbb-autocomplete-grid-optgroup>
      <sbb-autocomplete-grid-row>
        <sbb-autocomplete-grid-option value="1">Option 1</sbb-autocomplete-grid-option>
        <sbb-autocomplete-grid-cell>
          <sbb-autocomplete-grid-button icon-name="pen-small"></sbb-autocomplete-grid-button>
        </sbb-autocomplete-grid-cell>
      </sbb-autocomplete-grid-row>
      ...
    </sbb-autocomplete-grid-optgroup>
    <sbb-autocomplete-grid-optgroup>
      <sbb-autocomplete-grid-row>
        <sbb-autocomplete-grid-option value="100">Option 100</sbb-autocomplete-grid-option>
        <sbb-autocomplete-grid-cell>
          <sbb-autocomplete-grid-button icon-name="pen-small"></sbb-autocomplete-grid-button>
        </sbb-autocomplete-grid-cell>
      </sbb-autocomplete-grid-row>
      ...
    </sbb-autocomplete-grid-optgroup>
  </sbb-autocomplete-grid>
</sbb-form-field>

Size

The component has no size property but, when slotted in a sbb-form-field, it adapts to the parent size.

<sbb-form-field size="s">
  <label>Label</label>
  <input placeholder="Trigger element" />
  <sbb-autocomplete-grid> ... </sbb-autocomplete-grid>
</sbb-form-field>

Events

The sbb-autocomplete-grid-option emits the autocompleteoptionselected event when selected via user interaction.

Keyboard interaction

The options panel opens on focus, click or input events on the trigger element, or on ArrowDown keypress;
it can be closed on backdrop click, or using the Escape or Tab keys.

Keyboard Action
Down Arrow Navigate to the next option. Open the panel, if closed.
Up Arrow Navigate to the previous option.
Right Arrow Navigate to the next button.
Left Arrow Navigate to the previous button.
Enter Select the active option/button.
Escape Close the autocomplete panel.

Setting the autoSelectActiveOption property to true allows users
to automatically select the option reached via keyboard navigation as the input value,
without having to press the Enter key to confirm.

On the other hand, it's possible to use the requireSelection to clear the input
if the user does not explicitly select a value, via mouse click or keyboard selection.

Accessibility

The sbb-autocomplete-grid implements the ARIA combobox-grid interaction pattern.

The text input trigger specifies role="combobox" while the content of the pop-up applies role="grid".
The inner option and actions have role="gridcell", while the buttons inside the action have role="button".
Note that since the focus must always be on the connected input, those buttons can't be reached via Tab,
but only with arrow navigation; note also that when a button is reached, going up or down will move to the previous/next option
and not to the previous/next button.

The component preserves focus on the input trigger,
using aria-activedescendant to support navigation though the autocomplete options.

Complex Values

This component supports any types of values, including complex objects.
The type can be specified using the generic type parameter T of SbbAutocompleteGrid<T> and SbbAutocompleteGridOption<T>.

const values = [
  { value: 'value 1', name: 'Option 1' },
  { value: 'value 2', name: 'Option 2' },
];
<sbb-form-field>
  <input />
  <sbb-autocomplete-grid .displayWith="${(value) => value.name}">
    <sbb-autocomplete-grid-row>
      <sbb-autocomplete-grid-option .value="${values[0]}">Option 1</sbb-autocomplete-grid-option>
      ...
    </sbb-autocomplete-grid-row>
    <sbb-autocomplete-grid-row>
      <sbb-autocomplete-grid-option .value="${values[1]}">Option 2</sbb-autocomplete-grid-option>
      ...
    </sbb-autocomplete-grid-row>
  </sbb-autocomplete-grid>
</sbb-form-field>

displayWith function

When using complex values, the selection should most likely still be represented as text.
To achieve this, you can use the displayWith property which accepts a function.
This function receives the selected value and should return a string.

Please note that the parameter is the assigned value of the selected option which does not necessarily
align with the type information.

CSS Properties

Name Default Description
--sbb-autocomplete-z-index var(--sbb-overlay-default-z-index) To specify a custom stack order, the z-index can be overridden by defining this CSS variable. The default z-index of the component is set to var(--sbb-overlay-default-z-index) with a value of 1000.

Slots

Name Description
Use the unnamed slot to add sbb-autocomplete-grid-row or sbb-autocomplete-grid-optgroup elements to the sbb-autocomplete-grid.