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 Funktionale 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 Sinn & Zweck Community Assets Anleitung Power-Apps Digitale Werbebanner SAP App Icons File-Selector Info

Was macht die Komponente?

Ein File-Selector ist eine Komponente, die es Nutzenden ermöglicht, Dateien von seinem Gerät auszuwählen und hochzuladen.

Wann soll die Komponente eingesetzt werden?

  • Um Nutzenden die Möglichkeit zu geben, Dateien hochzuladen, wie z.B. Dokumente, Bilder oder Videos.
  • Um Formulare zu vervollständigen, die Dateianhänge erfordern.
  • Um Dateien für die Speicherung, Verarbeitung oder Weitergabe zu sammeln.

Regeln

  • Nutzende sollen Dateien entfernen können.
  • Der Fortschritt des Datei-Uploads kann Nutzenden angezeigt werden, insbesondere bei grösseren Dateien.
File-Selector-Dropzone
Anatomie
Anatomie der Komponente
Nummer Typ Beschreibung Optional Hinweis
1 Komponente sbb-secondary-button Nein Datei auswählen
2 Text Label Nein
3 Komponente sbb-secondary-button Nein Delete-Button
4 Text Dateigrösse Nein
5 Komponente sbb-form-error Nein
Demo

Spielwiese

Disabled Nein Ja Hintergrund White Milk Iron Charcoal Black
File Selector
Disabled
Multi
Multi Persistent
With Error
Only PDF
Multi Size S
HTML in Zwischenablage kopiert.
Implementation

The sbb-file-selector is a component which allows user to select one or more files from storage devices.
When files are selected, they appear as a list below the button.
For each file, the name and the size are displayed and an icon allows for deletion.
The component mimics the native <input type="file"/>; for the drag-and-drop variant, see
sbb-file-selector-dropzone

<sbb-file-selector></sbb-file-selector>

Slots

The error named slot can be used to display an error message using the sbb-form-error component.

<sbb-file-selector>
  <sbb-form-error slot="error">An error occurred during file upload.</sbb-form-error>
</sbb-file-selector>

States

User interaction can be disabled using the disabled property.

<sbb-file-selector disabled></sbb-file-selector>

Multiple and multipleMode

A single file can be selected by default; this can be changed setting the multiple property to true.

<sbb-file-selector multiple></sbb-file-selector>

The value of the multipleMode property determines whether added files should overwrite existing files (default) or be appended to them (persistent).

<sbb-file-selector multiple multiple-mode="persistent"></sbb-file-selector>

Accept

The accept property can be used to force the user to select one or more specific file types;
in the next example, only images are allowed.

<sbb-file-selector accept=".png,.jpg,.jpeg"></sbb-file-selector>

Style

The component has also two different sizes, m (default) and s, which can be changed using the size property.

<sbb-file-selector size="s"></sbb-file-selector>

Events

Whenever the selection changes, a fileChanged event is fired, whose event.detail property contains the list
of currently selected files. The list can also be retrieved using the public files getter.

Accessibility

It's possible to improve the component accessibility using the accessibilityLabel property; this will be set
as aria-label of the inner native input and read together with the visible button text.
It's suggested to have a different value for each variant, e.g.:

<sbb-file-selector accessibility-label="Select a file from hard disk"></sbb-file-selector>
<sbb-file-selector
  multiple
  accessibility-label="Select from hard disk - multiple selection allowed"
></sbb-file-selector>

Properties

Name Attribute Privacy Type Default Description
accept accept public string '' A comma-separated list of allowed unique file type specifiers.
accessibilityLabel accessibility-label public string '' This will be forwarded as aria-label to the native input element.
disabled disabled public boolean false Whether the component is disabled.
files - public Readonly<File>[] [] The list of selected files.
form - public HTMLFormElement | null Returns the form owner of this element.
multiple multiple public boolean false Whether more than one file can be selected.
multipleMode multiple-mode public 'default' | 'persistent' 'default' Whether the newly added files should override the previously added ones.
name name public string Name of the form element. Will be read from name attribute.
size size public 's' | 'm' 'm' / 's' (lean) Size variant, either s or m.
type - public string 'file' Form type of element.
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 string | null null The path of the first selected file. Empty string ('') if no file is selected
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
formResetCallback public void SbbFileSelectorCommonElementMixin
formStateRestoreCallback public state: FormRestoreState | null, _reason: FormRestoreReason void SbbFileSelectorCommonElementMixin
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 An event which is emitted each time the user modifies the value. Unlike the input event, the change event is not necessarily fired for each alteration to an element's value SbbFileSelectorCommonElementMixin
fileChanged CustomEvent<Readonly<File>[]> An event which is emitted each time the file list changes.
input Event An event which is emitted each time the value changes as a direct result of a user action. SbbFileSelectorCommonElementMixin

Slots

Name Description
error Use this to provide a sbb-form-error to show an error message.
Impressum Kontakt Datenschutz Cookie Einstellungen