primevue-mirror/components/lib/listbox/Listbox.d.ts

500 lines
14 KiB
TypeScript
Raw Normal View History

2023-03-01 10:20:57 +00:00
/**
*
* ListBox is used to select one or more values from a list of items.
*
* [Live Demo](https://www.primevue.org/listbox/)
*
* @module listbox
*
*/
2022-09-06 12:03:37 +00:00
import { InputHTMLAttributes, VNode } from 'vue';
2023-07-06 11:17:08 +00:00
import { ComponentHooks } from '../basecomponent';
import { ClassComponent, GlobalComponentConstructor, PTOptions } from '../ts-helpers';
2023-05-07 21:07:47 +00:00
import { VirtualScrollerItemOptions, VirtualScrollerPassThroughOptionType, VirtualScrollerProps } from '../virtualscroller';
export declare type ListboxPassThroughOptionType = ListboxPassThroughAttributes | ((options: ListboxPassThroughMethodOptions) => ListboxPassThroughAttributes | string) | string | null | undefined;
2023-05-07 21:07:47 +00:00
/**
* Custom passthrough(pt) option method.
*/
export interface ListboxPassThroughMethodOptions {
2023-07-06 12:01:33 +00:00
instance: any;
2023-05-07 21:07:47 +00:00
props: ListboxProps;
state: ListboxState;
context: ListboxContext;
}
2022-09-06 12:03:37 +00:00
2023-03-01 10:20:57 +00:00
/**
* Custom change event.
* @see {@link ListboxEmits.change}
*/
2022-09-06 12:03:37 +00:00
export interface ListboxChangeEvent {
/**
* Original event
*/
originalEvent: Event;
/**
* Selected option value
*/
value: any;
}
2023-03-01 10:20:57 +00:00
/**
* Custom filter event.
* @see {@link ListboxEmits.filter}
*/
2022-09-06 12:03:37 +00:00
export interface ListboxFilterEvent {
/**
* Original event
*/
originalEvent: Event;
/**
* Filter value
*/
value: string;
}
2023-05-07 21:07:47 +00:00
/**
* Custom passthrough(pt) options.
* @see {@link ListboxProps.pt}
*/
export interface ListboxPassThroughOptions {
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the root's DOM element.
2023-05-07 21:07:47 +00:00
*/
root?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the header's DOM element.
2023-05-07 21:07:47 +00:00
*/
header?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the filter container's DOM element.
2023-05-07 21:07:47 +00:00
*/
filterContainer?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the filter input's DOM element.
2023-05-07 21:07:47 +00:00
*/
filterInput?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the filter icon's DOM element.
2023-05-07 21:07:47 +00:00
*/
filterIcon?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the wrapper's DOM element.
2023-05-07 21:07:47 +00:00
*/
wrapper?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the VirtualScroller component.
2023-05-07 21:07:47 +00:00
* @see {@link VirtualScrollerPassThroughOptionType}
*/
virtualScroller?: VirtualScrollerPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the list's DOM element.
2023-05-07 21:07:47 +00:00
*/
list?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the item group's DOM element.
2023-05-07 21:07:47 +00:00
*/
itemGroup?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the item's DOM element.
2023-05-07 21:07:47 +00:00
*/
item?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the emptyMessage's DOM element.
2023-05-07 21:07:47 +00:00
*/
emptyMessage?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the hidden first focusable element's DOM element.
2023-05-07 21:07:47 +00:00
*/
hiddenFirstFocusableEl?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the hidden filter result's DOM element.
2023-05-07 21:07:47 +00:00
*/
hiddenFilterResult?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the hidden selected message's DOM element.
2023-05-07 21:07:47 +00:00
*/
hiddenSelectedMessage?: ListboxPassThroughOptionType;
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to the hidden last focusable element's DOM element.
2023-05-07 21:07:47 +00:00
*/
hiddenLastFocusableEl?: ListboxPassThroughOptionType;
2023-07-06 11:09:01 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to manage all lifecycle hooks
2023-07-06 11:09:01 +00:00
* @see {@link BaseComponent.ComponentHooks}
*/
hooks?: ComponentHooks;
2023-05-07 21:07:47 +00:00
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface ListboxPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in Listbox component.
*/
export interface ListboxState {
/**
* Current id state as a string.
*/
id: string;
/**
* Current focused state as a boolean.
* @defaultValue false
*/
focused: boolean;
/**
* Current filter value state as a string.
*/
filterValue: string;
/**
* Current focused item index as a number.
* @defaultValue -1
*/
focusedOptionIndex: number;
}
/**
* Defines current options in Listbox component.
*/
export interface ListboxContext {
/**
* Current selection state of the item as a boolean.
* @defaultValue false
*/
selected: boolean;
/**
* Current focus state of the item as a boolean.
* @defaultValue false
*/
focused: boolean;
/**
* Current disabled state of the item as a boolean.
* @defaultValue false
*/
disabled: boolean;
}
2023-03-01 10:20:57 +00:00
/**
* Defines valid properties in Listbox component.
*/
2022-09-06 12:03:37 +00:00
export interface ListboxProps {
/**
* Value of the component.
*/
modelValue?: any;
/**
* An array of selectitems to display as the available options.
*/
options?: any[] | undefined;
/**
* Property name or getter function to use as the label of an option.
*/
2023-03-01 10:20:57 +00:00
optionLabel?: string | ((data: any) => string) | undefined;
2022-09-06 12:03:37 +00:00
/**
* Property name or getter function to use as the value of an option, defaults to the option itself when not defined.
*/
2023-03-01 10:20:57 +00:00
optionValue?: string | ((data: any) => any) | undefined;
2022-09-06 12:03:37 +00:00
/**
* Property name or getter function to use as the disabled flag of an option, defaults to false when not defined.
*/
2023-03-01 10:20:57 +00:00
optionDisabled?: string | ((data: any) => boolean) | undefined;
2022-09-06 12:03:37 +00:00
/**
* Property name or getter function to use as the label of an option group.
*/
2023-03-01 10:20:57 +00:00
optionGroupLabel?: string | ((data: any) => string) | undefined;
2022-09-06 12:03:37 +00:00
/**
* Property name or getter function that refers to the children options of option group.
*/
2023-03-01 10:20:57 +00:00
optionGroupChildren?: string | ((data: any) => any[]) | undefined;
2022-09-06 12:03:37 +00:00
/**
* Inline style of inner list element.
*/
listStyle?: string | undefined;
/**
* When specified, disables the component.
2023-03-01 10:20:57 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
disabled?: boolean | undefined;
/**
* A property to uniquely identify an option.
*/
dataKey?: string | undefined;
/**
* When specified, allows selecting multiple values.
2023-03-01 10:20:57 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
multiple?: boolean | undefined;
/**
* Defines how multiple items can be selected, when true metaKey needs to be pressed to select or unselect an item and when set to false selection of each item can be toggled individually.
* On touch enabled devices, metaKeySelection is turned off automatically.
2023-04-24 17:19:57 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
metaKeySelection?: boolean | undefined;
/**
* When specified, displays a filter input at header.
2023-03-01 10:20:57 +00:00
* @defaultValue false
2022-09-06 12:03:37 +00:00
*/
filter?: boolean | undefined;
/**
* Placeholder text to show when filter input is empty.
*/
filterPlaceholder?: string | undefined;
/**
* Locale to use in filtering. The default locale is the host environment's current locale.
*/
filterLocale?: string | undefined;
/**
* Defines the filtering algorithm to use when searching the options.
2023-03-08 10:51:52 +00:00
* @defaultValue contains
2022-09-06 12:03:37 +00:00
*/
2023-03-27 08:09:36 +00:00
filterMatchMode?: 'contains' | 'startsWith' | 'endsWith' | string | undefined;
2022-09-06 12:03:37 +00:00
/**
* Fields used when filtering the options, defaults to optionLabel.
*/
filterFields?: string[] | undefined;
/**
2023-08-01 14:01:12 +00:00
* Used to pass all properties of the HTMLInputElement to the filter input inside the component.
2022-09-06 12:03:37 +00:00
*/
filterInputProps?: InputHTMLAttributes | undefined;
/**
* Whether to use the virtualScroller feature. The properties of VirtualScroller component can be used like an object in it.
2023-03-01 10:20:57 +00:00
* @type {VirtualScrollerProps}
2022-09-06 12:03:37 +00:00
*/
virtualScrollerOptions?: VirtualScrollerProps;
/**
* Whether to focus on the first visible or selected element.
2023-03-01 10:20:57 +00:00
* @defaultValue true
2022-09-06 12:03:37 +00:00
*/
autoOptionFocus?: boolean | undefined;
2022-09-14 11:26:01 +00:00
/**
* When enabled, the focused option is selected.
2023-03-01 10:20:57 +00:00
* @defaultValue false
2022-09-14 11:26:01 +00:00
*/
selectOnFocus?: boolean | undefined;
2022-09-06 12:03:37 +00:00
/**
* Text to be displayed in hidden accessible field when filtering returns any results. Defaults to value from PrimeVue locale configuration.
2023-03-08 11:02:08 +00:00
* @defaultValue '{0} results are available'
2022-09-06 12:03:37 +00:00
*/
filterMessage?: string | undefined;
/**
* Text to be displayed in hidden accessible field when options are selected. Defaults to value from PrimeVue locale configuration.
2023-03-08 11:02:08 +00:00
* @defaultValue '{0} items selected'
2022-09-06 12:03:37 +00:00
*/
selectionMessage?: string | undefined;
/**
* Text to be displayed in hidden accessible field when any option is not selected. Defaults to value from PrimeVue locale configuration.
2023-03-08 10:51:52 +00:00
* @defaultValue No selected item
2022-09-06 12:03:37 +00:00
*/
emptySelectionMessage?: string | undefined;
/**
* Text to display when filtering does not return any results. Defaults to value from PrimeVue locale configuration.
2023-03-08 10:51:52 +00:00
* @defaultValue No results found
2022-09-06 12:03:37 +00:00
*/
emptyFilterMessage?: string | undefined;
/**
* Text to display when there are no options available. Defaults to value from PrimeVue locale configuration.
2023-03-08 10:51:52 +00:00
* @defaultValue No results found
2022-09-06 12:03:37 +00:00
*/
emptyMessage?: string | undefined;
/**
* Index of the element in tabbing order.
*/
tabindex?: number | string | undefined;
2022-12-08 11:04:25 +00:00
/**
* Icon to display in filter input.
* @deprecated since v3.27.0. Use 'filtericon' slot.
2022-12-08 11:04:25 +00:00
*/
filterIcon?: string | undefined;
2022-09-06 12:03:37 +00:00
/**
* Defines a string value that labels an interactive element.
*/
2022-09-14 11:26:01 +00:00
'aria-label'?: string | undefined;
2022-09-06 12:03:37 +00:00
/**
* Identifier of the underlying input element.
*/
2022-09-14 11:26:01 +00:00
'aria-labelledby'?: string | undefined;
2023-05-07 21:07:47 +00:00
/**
2023-08-01 14:01:12 +00:00
* Used to pass attributes to DOM elements inside the component.
2023-05-07 21:07:47 +00:00
* @type {ListboxPassThroughOptions}
*/
pt?: PTOptions<ListboxPassThroughOptions>;
2023-05-25 13:53:42 +00:00
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
2022-09-06 12:03:37 +00:00
}
2023-03-01 10:20:57 +00:00
/**
* Defines valid slots in Listbox component.
*/
2022-09-06 12:03:37 +00:00
export interface ListboxSlots {
/**
* Custom header template.
* @param {Object} scope - header slot's params.
*/
2023-03-01 10:20:57 +00:00
header(scope: {
2022-09-06 12:03:37 +00:00
/**
* Value of the component
*/
value: any;
/**
* Displayed options
*/
options: any[];
2023-03-01 10:20:57 +00:00
}): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom footer template.
* @param {Object} scope - footer slot's params.
*/
2023-03-01 10:20:57 +00:00
footer(scope: {
2022-09-06 12:03:37 +00:00
/**
* Value of the component
*/
value: any;
/**
* Displayed options
*/
options: any[];
2023-03-01 10:20:57 +00:00
}): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom option template.
* @param {Object} scope - option slot's params.
*/
2023-03-01 10:20:57 +00:00
option(scope: {
2022-09-06 12:03:37 +00:00
/**
* Option instance
*/
option: any;
/**
* Index of the option
*/
index: number;
2023-03-01 10:20:57 +00:00
}): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom optiongroup template.
* @param {Object} scope - optiongroup slot's params.
*/
2023-03-01 10:20:57 +00:00
optiongroup(scope: {
2022-09-06 12:03:37 +00:00
/**
* Option instance
*/
option: any;
/**
* Index of the option
*/
index: number;
2023-03-01 10:20:57 +00:00
}): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom emptyfilter template.
*/
2023-03-01 10:20:57 +00:00
emptyfilter(): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom empty template.
*/
2023-03-01 10:20:57 +00:00
empty(): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom content template.
* @param {Object} scope - content slot's params.
*/
2023-03-01 10:20:57 +00:00
content(scope: {
2022-09-06 12:03:37 +00:00
/**
* An array of objects to display for virtualscroller
*/
items: any;
/**
* Style class of the component
*/
styleClass: string;
/**
* Referance of the content
* @param {HTMLElement} el - Element of 'ref' property
*/
2023-08-17 07:16:25 +00:00
contentRef: (el: any) => void;
2022-09-06 12:03:37 +00:00
/**
* Options of the items
* @param {number} index - Rendered index
2023-03-01 10:20:57 +00:00
* @return {VirtualScrollerItemOptions}
2022-09-06 12:03:37 +00:00
*/
2023-08-17 07:16:25 +00:00
getItemOptions: (index: number) => VirtualScrollerItemOptions;
2023-03-01 10:20:57 +00:00
}): VNode[];
2022-09-06 12:03:37 +00:00
/**
* Custom loader template.
* @param {Object} scope - loader slot's params.
*/
2023-03-01 10:20:57 +00:00
loader(scope: {
2022-09-06 12:03:37 +00:00
/**
* Options of the loader items for virtualscroller
*/
options: any[];
2023-03-01 10:20:57 +00:00
}): VNode[];
/**
* Custom filter icon template.
* @param {Object} scope - filter icon slot's params.
*/
filtericon(scope: {
/**
* Style class of the filter icon
*/
class: any;
}): VNode[];
2022-09-06 12:03:37 +00:00
}
2023-03-01 10:20:57 +00:00
/**
* Defines valid emits in Listbox component.
*/
export interface ListboxEmits {
2022-09-06 12:03:37 +00:00
/**
* Emitted when the value changes.
* @param {*} value - New value.
*/
2023-03-01 10:20:57 +00:00
'update:modelValue'(value: any): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke on value change.
* @param {ListboxChangeEvent} event - Custom change event.
*/
2023-03-01 10:20:57 +00:00
change(event: ListboxChangeEvent): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when the component receives focus.
* @param {Event} event - Browser event.
*/
2023-03-01 10:20:57 +00:00
focus(event: Event): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke when the component loses focus.
* @param {Event} event - Browser event.
*/
2023-03-01 10:20:57 +00:00
blur(event: Event): void;
2022-09-06 12:03:37 +00:00
/**
* Callback to invoke on filter input.
* @param {ListboxFilterEvent} event - Custom filter event.
*/
2023-03-01 10:20:57 +00:00
filter(event: ListboxFilterEvent): void;
}
2022-09-06 12:03:37 +00:00
2023-03-01 10:20:57 +00:00
/**
* **PrimeVue - Listbox**
*
* _ListBox is used to select one or more values from a list of items._
*
* [Live Demo](https://www.primevue.org/listbox/)
* --- ---
2023-03-03 10:55:20 +00:00
* ![PrimeVue](https://primefaces.org/cdn/primevue/images/logo-100.png)
2023-03-01 10:20:57 +00:00
*
* @group Component
*
*/
2022-09-14 11:26:01 +00:00
declare class Listbox extends ClassComponent<ListboxProps, ListboxSlots, ListboxEmits> {}
2022-09-06 12:03:37 +00:00
declare module '@vue/runtime-core' {
interface GlobalComponents {
2022-09-14 11:26:01 +00:00
Listbox: GlobalComponentConstructor<Listbox>;
2022-09-06 12:03:37 +00:00
}
}
export default Listbox;