Skip to content

File Input

Used to select and upload files or drag and drop files.

Importing

To use the file input component, first you need to register the component inside the page. You can register the component manually by importing the register function:

ts
import { register } from "@tapsioss/web-components/file-input";

register(); // Now the file input component is ready to use!
ts
import { registerFileInput } from "@tapsioss/web-components";

registerFileInput(); // Now the file input component is ready to use!

Also you can automatically register the component by importing it with the following approach:

ts
import "@tapsioss/web-components/file-input/element";

TIP

If you want to use all the component in your app, you can call registerAll at the root of your project.

ts
import { registerAll } from "@tapsioss/web-components";

registerAll(); // All the components are now available

In the React package, you can easily add the component using the following code:

ts
import { FileInput } from "@tapsioss/react-components";

Component Usage

html
<tapsi-file-input></tapsi-file-input>
tsx
<FileInput />

Properties

NameAttribute NameDescriptionTypeDefault Value
labelledBylabelledbyIdentifies the element (or elements) that labels the input.

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby
string""
loadingloadingIndicates the loading state of the component.

- If false, the component is not in a loading state.
- If true, a spinner will appear indicating the component is loading.
- If a number between 0 and 100, it shows the percentage of the loading state.
boolean | numberfalse
supportingTextsupporting-textConveys additional information below the file input, such as how it should
be used.
string""
multiplemultipleWhether the file input allows the user to select more than one file.booleanfalse
readOnlyreadonlyIndicates whether or not a user should be able to edit the file input's
value.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#readonly
booleanfalse
loadingTextloading-textThe text showing in file input when it is in loading state.string"در حال بارگذاری..."
errorTexterror-textThe error message that replaces supporting text when error is true. If
errorText is an empty string, then the supporting text will continue to
show.

This error message overrides the error message displayed by
reportValidity().
string""
errorerrorWhether the file input has error.booleanfalse
retryableErrorretryable-errorWhether the file input has retry button in error state.booleanfalse
capturecaptureUsed for showing camera for mobile devices.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#capture
string""
files-The list of selected files.FileList | nullnull
acceptacceptSpecifying what file format does the file input accepts.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept
string""
placeholderplaceholderA placeholder text for the input component when no file has been selected.string"انتخاب فایل"
labellabelThe label of the file input.
- If the hideLabel property is true, the label will be hidden visually
but still accessible to screen readers.
- Otherwise, a visible label element will be rendered.

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label
string""
hideLabelhide-labelWhether to hide the label or not.booleanfalse
requiredrequiredIndicates that the user must specify a value for the input before the
owning form can be submitted and will render an error state when
reportValidity() is invoked when value is empty.

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required
booleanfalse
autofocusautofocusIndicates that the element should be focused on page load.

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus
booleanfalse
valuevalueThe current value of the input. It is always a string.string""

Methods

NameDescriptionParameters
resetReset the text field to its default value.

Slots

NameValueDescription
PLACEHOLDER_ICONplaceholder-iconThe slot for icon placeholder.

TIP

The value of slots are available for developer as JavaScript Variables:

ts
// Option 1
import { FileInputSlots } from "@tapsioss/web-components";

// Option 2
import { Slots } from "@tapsioss/web-components/file-input";
ts
// Option 1
import { FileInputSlots } from "@tapsioss/react-components";

// Option 2
import { Slots } from "@tapsioss/react-components/FileInput";

Events

NameDescriptionTypeBubblesCancelable
changeFires 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.Event
inputFires when the value of an input element has been changed as a direct result of a user action.Event
retryFires when the retry button is clicked.RetryEvent
clearFires when user clicks on the clear button for reseting the input valueClearEvent

TIP

Event details are available as JavaScript variables:

ts
// Option 1
import {
 RetryEvent,
 ClearEvent
} from "@tapsioss/web-components/file-input";

// Option 2
import {
 FileInputRetryEvent,
 FileInputClearEvent
} from "@tapsioss/web-components";

You can have access to the event name using the type property:

ts
// Option 1
element.addEventListener(RetryEvent.type, handleRetry);
element.addEventListener(ClearEvent.type, handleClear);

// Option 2
element.addEventListener(FileInputRetryEvent.type, handleRetry);
element.addEventListener(FileInputClearEvent.type, handleClear);

Created with 🧡