Refactor #5548 - For Dropdown

pull/5677/head
tugcekucukoglu 2024-04-08 15:58:58 +03:00
parent 285790f12c
commit f6751003f9
3 changed files with 16 additions and 63 deletions

View File

@ -9,7 +9,6 @@
*/ */
import { TransitionProps, VNode } from 'vue'; import { TransitionProps, VNode } from 'vue';
import { ComponentHooks } from '../basecomponent'; import { ComponentHooks } from '../basecomponent';
import { InputTextPassThroughOptions } from '../inputtext';
import { PassThroughOptions } from '../passthrough'; import { PassThroughOptions } from '../passthrough';
import { ClassComponent, DesignToken, GlobalComponentConstructor, HintedString, PassThrough } from '../ts-helpers'; import { ClassComponent, DesignToken, GlobalComponentConstructor, HintedString, PassThrough } from '../ts-helpers';
import { VirtualScrollerItemOptions, VirtualScrollerPassThroughOptionType, VirtualScrollerProps } from '../virtualscroller'; import { VirtualScrollerItemOptions, VirtualScrollerPassThroughOptionType, VirtualScrollerProps } from '../virtualscroller';
@ -48,20 +47,6 @@ export interface DropdownPassThroughMethodOptions<T> {
global: object | undefined; global: object | undefined;
} }
/**
* Custom shared passthrough(pt) option method.
*/
export interface DropdownSharedPassThroughMethodOptions {
/**
* Defines valid properties.
*/
props: DropdownProps;
/**
* Defines current inline state.
*/
state: DropdownState;
}
/** /**
* Custom change event. * Custom change event.
* @see {@link DropdownEmits.change} * @see {@link DropdownEmits.change}
@ -102,10 +87,9 @@ export interface DropdownPassThroughOptions<T = any> {
*/ */
root?: DropdownPassThroughOptionType<T>; root?: DropdownPassThroughOptionType<T>;
/** /**
* Used to pass attributes to the InputText component. * Used to pass attributes to the input's DOM element.
* @see {@link InputTextPassThroughOptions}
*/ */
input?: InputTextPassThroughOptions<DropdownSharedPassThroughMethodOptions>; input?: DropdownPassThroughOptionType<T>;
/** /**
* Used to pass attributes to the clear icon's DOM element. * Used to pass attributes to the clear icon's DOM element.
*/ */
@ -131,10 +115,9 @@ export interface DropdownPassThroughOptions<T = any> {
*/ */
filterContainer?: DropdownPassThroughOptionType<T>; filterContainer?: DropdownPassThroughOptionType<T>;
/** /**
* Used to pass attributes to the InputText component. * Used to pass attributes to the filter input's DOM element.
* @see {@link InputTextPassThroughOptions}
*/ */
filterInput?: InputTextPassThroughOptions<DropdownSharedPassThroughMethodOptions>; filterInput?: DropdownPassThroughOptionType<T>;
/** /**
* Used to pass attributes to the filter icon's DOM element. * Used to pass attributes to the filter icon's DOM element.
*/ */

View File

@ -1,6 +1,6 @@
<template> <template>
<div ref="container" :id="id" :class="cx('root')" @click="onContainerClick" v-bind="ptmi('root')"> <div ref="container" :id="id" :class="cx('root')" @click="onContainerClick" v-bind="ptmi('root')">
<InputText <input
v-if="editable" v-if="editable"
ref="focusInput" ref="focusInput"
:id="inputId" :id="inputId"
@ -11,9 +11,6 @@
:placeholder="placeholder" :placeholder="placeholder"
:tabindex="!disabled ? tabindex : -1" :tabindex="!disabled ? tabindex : -1"
:disabled="disabled" :disabled="disabled"
:invalid="invalid"
:variant="variant"
:unstyled="unstyled"
autocomplete="off" autocomplete="off"
role="combobox" role="combobox"
:aria-label="ariaLabel" :aria-label="ariaLabel"
@ -22,11 +19,12 @@
:aria-expanded="overlayVisible" :aria-expanded="overlayVisible"
:aria-controls="id + '_list'" :aria-controls="id + '_list'"
:aria-activedescendant="focused ? focusedOptionId : undefined" :aria-activedescendant="focused ? focusedOptionId : undefined"
:aria-invalid="invalid || undefined"
@focus="onFocus" @focus="onFocus"
@blur="onBlur" @blur="onBlur"
@keydown="onKeyDown" @keydown="onKeyDown"
@input="onEditableInput" @input="onEditableInput"
:pt="ptm('input')" v-bind="ptm('input')"
/> />
<span <span
v-else v-else
@ -79,7 +77,7 @@
<slot name="header" :value="modelValue" :options="visibleOptions"></slot> <slot name="header" :value="modelValue" :options="visibleOptions"></slot>
<div v-if="filter" :class="cx('header')" v-bind="ptm('header')"> <div v-if="filter" :class="cx('header')" v-bind="ptm('header')">
<div :class="cx('filterContainer')" v-bind="ptm('filterContainer')"> <div :class="cx('filterContainer')" v-bind="ptm('filterContainer')">
<InputText <input
ref="filterInput" ref="filterInput"
type="text" type="text"
:value="filterValue" :value="filterValue"
@ -87,9 +85,6 @@
@vue:updated="onFilterUpdated" @vue:updated="onFilterUpdated"
:class="cx('filterInput')" :class="cx('filterInput')"
:placeholder="filterPlaceholder" :placeholder="filterPlaceholder"
:invalid="invalid"
:variant="variant"
:unstyled="unstyled"
role="searchbox" role="searchbox"
autocomplete="off" autocomplete="off"
:aria-owns="id + '_list'" :aria-owns="id + '_list'"
@ -97,7 +92,7 @@
@keydown="onFilterKeyDown" @keydown="onFilterKeyDown"
@blur="onFilterBlur" @blur="onFilterBlur"
@input="onFilterChange" @input="onFilterChange"
:pt="ptm('filterInput')" v-bind="ptm('filterInput')"
/> />
<slot name="filtericon" :class="cx('filterIcon')"> <slot name="filtericon" :class="cx('filterIcon')">
<component :is="filterIcon ? 'span' : 'SearchIcon'" :class="[cx('filterIcon'), filterIcon]" v-bind="ptm('filterIcon')" /> <component :is="filterIcon ? 'span' : 'SearchIcon'" :class="[cx('filterIcon'), filterIcon]" v-bind="ptm('filterIcon')" />
@ -190,7 +185,6 @@ import ChevronDownIcon from 'primevue/icons/chevrondown';
import SearchIcon from 'primevue/icons/search'; import SearchIcon from 'primevue/icons/search';
import SpinnerIcon from 'primevue/icons/spinner'; import SpinnerIcon from 'primevue/icons/spinner';
import TimesIcon from 'primevue/icons/times'; import TimesIcon from 'primevue/icons/times';
import InputText from 'primevue/inputtext';
import OverlayEventBus from 'primevue/overlayeventbus'; import OverlayEventBus from 'primevue/overlayeventbus';
import Portal from 'primevue/portal'; import Portal from 'primevue/portal';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
@ -307,7 +301,7 @@ export default {
this.overlayVisible = true; this.overlayVisible = true;
this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : this.editable ? -1 : this.findSelectedOptionIndex(); this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : this.editable ? -1 : this.findSelectedOptionIndex();
isFocus && DomHandler.focus(this.editable ? this.$refs.focusInput.$el : this.$refs.focusInput); isFocus && DomHandler.focus(this.$refs.focusInput);
}, },
hide(isFocus) { hide(isFocus) {
const _hide = () => { const _hide = () => {
@ -318,7 +312,7 @@ export default {
this.searchValue = ''; this.searchValue = '';
this.resetFilterOnHide && (this.filterValue = null); this.resetFilterOnHide && (this.filterValue = null);
isFocus && DomHandler.focus(this.editable ? this.$refs.focusInput.$el : this.$refs.focusInput); isFocus && DomHandler.focus(this.$refs.focusInput);
}; };
setTimeout(() => { setTimeout(() => {
@ -986,7 +980,6 @@ export default {
ripple: Ripple ripple: Ripple
}, },
components: { components: {
InputText,
VirtualScroller, VirtualScroller,
Portal, Portal,
TimesIcon, TimesIcon,

View File

@ -3289,7 +3289,7 @@
"name": "input", "name": "input",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "InputTextPassThroughOptions<AutoCompleteSharedPassThroughMethodOptions>", "type": "AutoCompletePassThroughOptionType | InputTextPassThroughOptions<AutoCompleteSharedPassThroughMethodOptions>",
"default": "", "default": "",
"description": "Used to pass attributes to the InputText component." "description": "Used to pass attributes to the InputText component."
}, },
@ -23988,29 +23988,6 @@
], ],
"methods": [] "methods": []
}, },
"DropdownSharedPassThroughMethodOptions": {
"description": "Custom shared passthrough(pt) option method.",
"relatedProp": "",
"props": [
{
"name": "props",
"optional": false,
"readonly": false,
"type": "DropdownProps",
"default": "",
"description": "Defines valid properties."
},
{
"name": "state",
"optional": false,
"readonly": false,
"type": "DropdownState",
"default": "",
"description": "Defines current inline state."
}
],
"methods": []
},
"DropdownChangeEvent": { "DropdownChangeEvent": {
"description": "Custom change event.", "description": "Custom change event.",
"relatedProp": "DropdownEmits.change", "relatedProp": "DropdownEmits.change",
@ -24073,9 +24050,9 @@
"name": "input", "name": "input",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "InputTextPassThroughOptions<DropdownSharedPassThroughMethodOptions>", "type": "DropdownPassThroughOptionType<T>",
"default": "", "default": "",
"description": "Used to pass attributes to the InputText component." "description": "Used to pass attributes to the input's DOM element."
}, },
{ {
"name": "clearIcon", "name": "clearIcon",
@ -24129,9 +24106,9 @@
"name": "filterInput", "name": "filterInput",
"optional": true, "optional": true,
"readonly": false, "readonly": false,
"type": "InputTextPassThroughOptions<DropdownSharedPassThroughMethodOptions>", "type": "DropdownPassThroughOptionType<T>",
"default": "", "default": "",
"description": "Used to pass attributes to the InputText component." "description": "Used to pass attributes to the filter input's DOM element."
}, },
{ {
"name": "filterIcon", "name": "filterIcon",