Prinzipien Grundlagen Barrierefreiheit Design System Guidelines Deutsch Français Italiano English Unsere Gestaltungsprinzipien Nutzerzentriert Wiedererkennbar Inklusiv Reduziert Ganzheitlich Selbsterklärend Aufgabenorientiert Passend SBB Markenportal Logo Digitale Uhr Nutzungsrechte Basis-Farben Zusätzliche Farben Off-Brand Farben Icons Fahrplan-Icons Piktogramme Über Barrierefreiheit Über diesen Guide Kontakt Weitere Informationen Product Owner User Research Interaction Design Visual Design Development Content Design Testing Was ist ein Design System?​ Designing Coding FAQ Hilfe Prozess Contribution Kontakt Übersicht Basis Komponenten Übersicht Releases Design Tokens Komponenten Übersicht Basis Informationen Übersicht Basis Komponenten Übersicht Power-Apps Digitale Werbebanner SAP AI Design: Grundlagen App Icons Chip-Group Info

Was macht die Komponente?

Sie beinhaltet die Chip-Komponente.

Wann soll die Komponente eingesetzt werden?

  • Nur in Kombination mit der Chip-Komponente.
Chip Form-Field Autocomplete Select
Demo Default
Disabled
Readonly
Size S
Size L
With Autocomplete
With Autocomplete Negative
With Separator Keys
HTML in Zwischenablage kopiert.
Implementation

The sbb-chip-group component is a container for one or multiple sbb-chip.
Generally, it is used in combination with an sbb-form-field to allow the input of multiple string values.

The value property reflects the list of slotted chips. Adding or removing an sbb-chip updates the value property, and vice versa.

<sbb-form-field>
  <label>Field label</label>
  <sbb-chip-group name="field-name">
    <sbb-chip value="Value 1"></sbb-chip>
    ...
    <input />
  </sbb-chip-group>
</sbb-form-field>

Slots

Use the unnamed slot to provide the sbb-chip and the input field.

States

The sbb-chip-group has a disabled and a readonly state and reacts to the respective input properties.
The disabled/readonly properties are proxied to the slotted sbb-chips.

<sbb-form-field>
  <sbb-chip-group name="field-name">
    <sbb-chip value="Value 1"></sbb-chip>
    ...
    <input disabled />
    <!-- Or -->
    <input readonly />
  </sbb-chip-group>
</sbb-form-field>

Style

The sbb-chip-group has a negative variant. If within an sbb-form-field, the properties automatically sync.

<sbb-form-field negative>
  <sbb-chip-group name="field-name">
    <sbb-chip value="Value 1"></sbb-chip>
    ...
    <input />
  </sbb-chip-group>
</sbb-form-field>

Usage

By default, when the user presses Enter, the sbb-chip-group will create a new sbb-chip and add it to the slotted elements.

Consumers can customize or prevent this behavior by listening to the chipinputtokenend event.

<!-- Preventing the event will stop the chip-group from converting the input value into a chip -->
<sbb-chip-group name="field-name" @chipinputtokenend="${(ev)" ="">
  ev.preventDefault()}> ...
  <input />
</sbb-chip-group>
<!-- Use the event.detail object to override the default behavior -->
<sbb-chip-group
  name="field-name"
  @chipinputtokenend=${(ev: CustomEvent<SbbChipInputTokenEndEventDetails>) => {
    ev.detail.setValue(transformedValue);
    ev.detail.setLabel('Custom label');
  }}>
  ...
  <input />
</sbb-chip-group>

Use within forms

The sbb-chip-group is a form-associated element that can be part of a form. Its value is an array of strings.

Note: The name must be set on the sbb-chip-group, not on the input

<form>
  <sbb-form-field>
    <sbb-chip-group name="field-name">
      <sbb-chip value="Value 1"></sbb-chip>
      ...
      <input />
    </sbb-chip-group>
  </sbb-form-field>
</form>

Use with Autocomplete

It is possible to combine the functionalities of chip-group and the sbb-autocomplete.

In this scenario, selecting an option will create a new chip using the option value.

<sbb-form-field>
  <sbb-chip-group name="field-name">
    <sbb-chip value="Value 1"></sbb-chip>
    ...
    <input />
  </sbb-chip-group>
  <sbb-autocomplete>
    <sbb-option value="Option A">Option A</sbb-option>
    ...
  </sbb-autocomplete>
</sbb-form-field>

Custom 'separator-keys'

By default, the sbb-chip-group creates a new chip on Enter key press.

Consumers can customize the array of keys that will trigger the chip creation by using the separatorKeys property.

<sbb-chip-group name="field-name" separator-keys='["Enter", "Space"]'> ... </sbb-chip-group>

Keyboard interaction

At any time, only a single chip (usually, the last one) is focusable and part of the tab order. Users can move between them using the arrow keys.

Keyboard Action
Enter When the input is focused, add a new chip.
Backspace When the input is empty & focused, focus the last chip.
Backspace When the sbb-chip is focused, delete it.
Left/Up Arrow Move the next sbb-chip.
Right/Down Arrow Move the previous sbb-chip.

Accessibility

The sbb-chip-group follows the grid aria pattern.

Complex Values

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

To render the complex value, the displayWith function can be used to map
the value to a string represented in the created chips.

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

<sbb-form-field>
  <label>Label</label>
  <sbb-chip-group
    name="chip-group-1"
    .displayWith=${(value) => value.property}
    .value=${[{property: 'Option 1', otherProp: 'test'}]}
  >
    <input placeholder="Placeholder" />
  </sbb-chip-group>
  <sbb-autocomplete>
    <sbb-option .value=${{property: 'Option 3', otherProp: 'test'}}>Option 3</sbb-option>
    <sbb-option .value=${{property: 'Option 4', otherProp: 'test'}}>Option 4</sbb-option>
  </sbb-autocomplete>
</sbb-form-field>

Properties

Name Attribute Privacy Type Default Description
disabled disabled public boolean false Whether the component is disabled.
displayWith - public ((value: T) => string) | null null Function that maps a chip's value to its display value.
form - public HTMLFormElement | null Returns the form owner of this element.
name name public string Name of the form element. Will be read from name attribute.
negative negative public boolean false Negative coloring variant flag.
required required public boolean false Whether the component is required.
separatorKeys separator-keys public string[] ['Enter'] The array of keys that will trigger a chipinputtokenend event. Default \['Enter']
validationMessage - public string Returns the current error message, if available, which corresponds to the current validation state. Please note that only one message is returned at a time (e.g. if multiple validity states are invalid, only the chronologically first one is returned until it is fixed, at which point the next message might be returned, if it is still applicable). Also, a custom validity message (see below) has precedence over native validation messages.
validity - public ValidityState Returns the ValidityState object for this element.
value value public (T = string[]) | null Value of the form element.
willValidate - public boolean Returns true if this element will be validated when the form is submitted; false otherwise.

Methods

Name Privacy Description Parameters Return Inherited From
checkValidity public Returns true if this element has no validity problems; false otherwise. Fires an invalid event at the element in the latter case. boolean SbbFormAssociatedMixin
reportValidity public Returns true if this element has no validity problems; otherwise, returns false, fires an invalid event at the element, and (if the event isn't canceled) reports the problem to the user. boolean SbbFormAssociatedMixin
setCustomValidity public Sets the custom validity message for this element. Use the empty string to indicate that the element does not have a custom validity error. message: string void SbbFormAssociatedMixin

Events

Name Type Description Inherited From
change Event The change event is fired when the user modifies the element's value. Unlike the input event, the change event is not necessarily fired for each alteration to an element's value.
chipinputtokenend CustomEvent<SbbChipInputTokenEndEventDetails> Notifies that a chip is about to be created. Can be prevented.
input InputEvent The input event fires when the value has been changed as a direct result of a user action.

Slots

Name Description
Use the unnamed slot to add sbb-chip elements.