Skip to main content
Light Dark System

File

<zn-file> | ZnFile
Since 1.0 experimental

File controls allow selecting an arbitrary number of files for uploading.

<zn-file multiple clearable></zn-file>

Examples

Label

<zn-file label="File Upload"></zn-file>

Droparea

<zn-file accept="text/plain,image/*" multiple droparea></zn-file>

Help Text

<zn-file help-text="You can drag and drop files here"></zn-file>

Multiple Upload


<zn-file multiple></zn-file>

Hide Value


<zn-file hide-value></zn-file>

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.

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

<script type="module" src="https://cdn.jsdelivr.net/npm/@kubex/zinc@1.0.0/dist/components/file/file.js"></script>

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

import 'https://cdn.jsdelivr.net/npm/@kubex/zinc@1.0.0/dist/components/file/file.js';

To import this component using a bundler:

import '@kubex/zinc/dist/components/file/file.js';

Slots

Name Description
label The file control’s label. Alternatively, you can use the label attribute.
help-text Text that describes how to use the file control. Alternatively, you can use the help-text attribute.
droparea-icon Optional droparea icon to use instead of the default. Works best with <zn-icon>.
trigger Optional content to be used as trigger instead of the default content. Opening the file dialog on click and as well as drag and drop will work for this content. Following attributes will no longer work: label, droparea, help-text, size, hide-value. Also if using the disabled attribute, the disabled styling will not be applied and must be taken care of yourself.

Learn more about using slots.

Properties

Name Description Reflects Type Default
files The selected files as a FileList object containing a list of File objects. The FileList behaves like an array, so you can get the number of selected files via its length property. see MDN - -
name The name of the file control, submitted as a name/value pair with form data. string ''
value The value of the file control contains a string that represents the path of the selected file. If multiple files are selected, the value represents the first file in the list. If no file is selected, the value is an empty string. Beware that the only valid value when setting a file control is an empty string! see MDN - -
defaultValue The default value of the form control. Primarily used for resetting the form control. string ''
size The file control’s size. 'small' | 'medium' | 'large' 'medium'
label The file control’s label. If you need to display HTML, use the label slot instead. string ''
clearable If this is set, then the only way to remove files is to click the cross next to them. boolean false
helpText
help-text
The file control’s help text. If you need to display HTML, use the help-text slot instead. string ''
disabled Disables the file control. boolean false
droparea Draw the file control as a drop area boolean false
accept Comma separated list of supported file types see MDN string ''
capture Specifies the types of files that the server accepts. Can be set either to user or environment. Works only when not using a droparea! see MDN 'user' | 'environment' -
multiple Indicates whether the user can select more than one file. Has no effect if webkitdirectory is set. see MDN boolean false
webkitdirectory Indicates that the file control should let the user select directories instead of files. When a directory is selected, the directory and its entire hierarchy of contents are included in the set of selected items. Note: This is a non-standard attribute but is supported in the major browsers. see MDN 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
hideValue
hide-value
Suppress the value from being displayed in the file control boolean false
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
zn-blur Emitted when the control loses focus. -
zn-change Emitted when an alteration to the control’s value is committed by the user. -
zn-error Emitted when multiple files are selected via drag and drop, without the multiple property being set. -
zn-focus Emitted when the control gains focus. -
zn-input Emitted when the control receives input. -

Learn more about events.

Methods

Name Description Arguments
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
focus() Sets focus on the button or droparea. options: FocusOptions
blur() Removes focus from the button or droparea. -

Learn more about methods.

Parts

Name Description
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.
button-wrapper The wrapper around the button and text value.
button The zn-button acting as a file input.
button__base The zn-button’s exported base part.
value The chosen files or placeholder text for the file input.
droparea The element wrapping the drop zone.
droparea-background The background of the drop zone.
droparea-icon The container that wraps the icon for the drop zone.
droparea-value The text for the drop zone.
trigger The container that wraps the trigger.

Learn more about customizing CSS parts.

Animations

Name Description
file.iconDrop The animation to use for the file icon when a file is dropped
file.text.disappear The disappear animation to use for the file placeholder text when a file is dropped
file.text.appear The appear animation to use for the file placeholder text when a file is dropped

Learn more about customizing animations.

Dependencies

This component automatically imports the following dependencies.

  • <zn-button>
  • <zn-example>
  • <zn-icon>
  • <zn-tooltip>