Skip to main content
Yoummday Light Light Dark System

File Upload

<sl-file-upload> | SlFileUpload
Since 2.44.0 stable

Drop or select files to upload with a form

Extends SlInput and therefore inherits properties, events and methods from it.
Try not to combine unneccessary or contradictory properties like type="date" with the picker.

Select CSV file or drag it here
Only PDF allowed. Drop it like it’s hot.
Read the following carefully to learn how you can upload something Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Check also your console for real FormData
Serialize form
<form id="demo">
  <sl-file-upload name="file1" required></sl-file-upload>
  <sl-file-upload name="file2" accept=".csv">
     <sl-txt p>Select <sl-txt span overline>CSV</sl-txt> file or drag it here</sl-txt>
  </sl-file-upload>
  <sl-file-upload icon="" style="--height: 30px" name="file3" accept=".pdf">
   <div>Only <sl-txt span overline>PDF</sl-txt> allowed. Drop it like it's hot.</div>
  </sl-file-upload>
  <sl-file-upload name="file4" icon="mdi:emoticon-poop" noPreview>
    <sl-txt h4>Read the following carefully to learn how you can upload something</sl-txt>
    <sl-txt p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</sl-txt>
  </sl-file-upload>
  <pre>Check also your console for real FormData</pre>
  <sl-button type="submit">Serialize form</sl-button>
</form>

<script type="module">
  const form = document.getElementById('demo');
  form.addEventListener('submit', (e) => {
    console.log(new FormData(e.currentTarget))
  })
  makeFormDemo('demo');
</script>

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Script Import Bundler React

To import this component from the CDN using a script tag:

<script type="module" src="https://v2-48-10.yoummday-theme.pages.dev/components/file-upload/file-upload.js"></script>

To import this component from the CDN using a JavaScript import:

import 'https://v2-48-10.yoummday-theme.pages.dev/components/file-upload/file-upload.js';

To import this component using a bundler:

import '@yoummday/ymmd-shoelace/dist/components/file-upload/file-upload.js';

To import this component as a React component:

import SlFileUpload from '@yoummday/ymmd-shoelace/dist/react/file-upload';

Slots

Name Description
(default) The default slot for rendering supportive text
label The input’s label. Alternatively, you can use the label attribute.
prefix Used to prepend a presentational icon or similar element to the input.
suffix Used to append a presentational icon or similar element to the input.
clear-icon An icon to use in lieu of the default clear icon.
show-password-icon An icon to use in lieu of the default show password icon.
hide-password-icon An icon to use in lieu of the default hide password icon.
help-text Text that describes how to use the input. Alternatively, you can use the help-text attribute.

Learn more about using slots.

Properties

Name Description Reflects Type Default
accept Comma separated list of file extensions that are allowed to be uploaded string '.jpg,.jpeg,.png'
noPreview Hide the preview of the uploaded file boolean false
icon Icon to display in the drop area string 'mdi:cloud-upload'
files Read files from the input - -
type The type of input. Works the same as a native <input> element, but only a subset of types are supported. Defaults to text. 'date' | 'datetime-local' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'time' | 'url' 'text'
name The name of the input, submitted as a name/value pair with form data. string ''
value The current value of the input, submitted as a name/value pair with form data. string ''
defaultValue The default value of the form control. Primarily used for resetting the form control. string ''
size The input’s size. 'small' | 'medium' | 'large' 'medium'
filled Draws a filled input. boolean false
pill Draws a pill-style input with rounded edges. boolean false
label The input’s label. If you need to display HTML, use the label slot instead. string ''
helpText
help-text
The input’s help text. If you need to display HTML, use the help-text slot instead. string ''
clearable Adds a clear button when the input is not empty. boolean false
disabled Disables the input. boolean false
placeholder Placeholder text to show as a hint when the input is empty. string ''
readonly Makes the input readonly. boolean false
passwordToggle
password-toggle
Adds a button to toggle the password’s visibility. Only applies to password types. boolean false
passwordVisible
password-visible
Determines whether or not the password is currently visible. Only applies to password input types. boolean false
noSpinButtons
no-spin-buttons
Hides the browser’s built-in increment/decrement spin buttons for number inputs. boolean false
form By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work. string ''
required Makes the input a required field. boolean false
pattern A regular expression pattern to validate input against. string -
minlength The minimum length of input that will be considered valid. number -
maxlength The maximum length of input that will be considered valid. number -
min The input’s minimum value. Only applies to date and number input types. number | string -
max The input’s maximum value. Only applies to date and number input types. number | string -
step Specifies the granularity that the value must adhere to, or the special value any which means no stepping is implied, allowing any numeric value. Only applies to date and number input types. number | 'any' -
autocapitalize Controls whether and how text input is automatically capitalized as it is entered by the user. 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters' -
autocorrect Indicates whether the browser’s autocorrect feature is on or off. 'off' | 'on' -
autocomplete Specifies what permission the browser has to provide assistance in filling out form field values. Refer to this page on MDN for available values. string -
autofocus Indicates that the input should receive focus on page load. boolean -
enterkeyhint Used to customize the label or icon of the Enter key on virtual keyboards. 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' -
spellcheck Enables spell checking on the input. boolean true
inputmode Tells the browser what type of data will be entered by the user, allowing it to display the appropriate virtual keyboard on supportive devices. 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url' -
valueAsDate Gets or sets the current value as a Date object. Returns null if the value can’t be converted. This will use the native <input type="{{type}}"> implementation and may result in an error. - -
valueAsNumber Gets or sets the current value as a number. Returns NaN if the value can’t be converted. - -
validity Gets the validity state object - -
validationMessage Gets the validation message - -
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Events

Name React Event Description Event Detail
sl-blur onSlBlur Emitted when the control loses focus. -
sl-change onSlChange Emitted when an alteration to the control’s value is committed by the user. -
sl-clear onSlClear Emitted when the clear button is activated. -
sl-focus onSlFocus Emitted when the control gains focus. -
sl-input onSlInput Emitted when the control receives input. -
sl-invalid onSlInvalid Emitted when the form control has been checked for validity and its constraints aren’t satisfied. -

Learn more about events.

Methods

Name Description Arguments
focus() Sets focus on the input. options: FocusOptions
blur() Removes focus from the input. -
select() Selects all the text in the input. -
setSelectionRange() Sets the start and end positions of the text selection (0-based). selectionStart: number, selectionEnd: number, selectionDirection: 'forward' | 'backward' | 'none'
setRangeText() Replaces a range of text with a new string. replacement: string, start: number, end: number, selectMode: 'select' | 'start' | 'end' | 'preserve'
showPicker() Displays the browser picker for an input element (only works if the browser supports it for the input type). -
stepUp() Increments the value of a numeric input type by the value of the step attribute. -
stepDown() Decrements the value of a numeric input type by the value of the step attribute. -
checkValidity() Checks for validity but does not show a validation message. Returns true when valid and false when invalid. -
getForm() Gets the associated form, if one exists. -
reportValidity() Checks for validity and shows the browser’s validation message if the control is invalid. -
setCustomValidity() Sets a custom validation message. Pass an empty string to restore validity. message: string

Learn more about methods.

Custom Properties

Name Description Default
--border set to ‘none’ to not render a border
--min-height set a min-height

Learn more about customizing CSS custom properties.

Parts

Name Description
base The component’s base wrapper.
form-control The form control that wraps the label, input, and help text.
form-control-label The label’s wrapper.
form-control-input The input’s wrapper.
form-control-help-text The help text’s wrapper.
input The internal <input> control.
prefix The container that wraps the prefix.
clear-button The clear button.
password-toggle-button The password toggle button.
suffix The container that wraps the suffix.

Learn more about customizing CSS parts.

Dependencies

This component automatically imports the following dependencies.

  • <sl-icon>