Skip to content

Commit

Permalink
Refactor #5426 - For MultiSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Mar 18, 2024
1 parent d79ef67 commit 89e01ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
34 changes: 21 additions & 13 deletions components/lib/multiselect/MultiSelect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
*/
import { ButtonHTMLAttributes, HTMLAttributes, InputHTMLAttributes, TransitionProps, VNode } from 'vue';
import { ComponentHooks } from '../basecomponent';
import { InputTextPassThroughOptions } from '../inputtext';
import { PassThroughOptions } from '../passthrough';
import { ClassComponent, GlobalComponentConstructor, PassThrough, HintedString } from '../ts-helpers';
import { ClassComponent, GlobalComponentConstructor, HintedString, PassThrough } from '../ts-helpers';
import { VirtualScrollerItemOptions, VirtualScrollerPassThroughOptionType, VirtualScrollerProps } from '../virtualscroller';

export declare type MultiSelectPassThroughOptionType = MultiSelectPassThroughAttributes | ((options: MultiSelectPassThroughMethodOptions) => MultiSelectPassThroughAttributes | string) | string | null | undefined;
Expand Down Expand Up @@ -51,6 +52,20 @@ export interface MultiSelectPassThroughMethodOptions {
global: object | undefined;
}

/**
* Custom shared passthrough(pt) option method.
*/
export interface MultiSelectSharedPassThroughMethodOptions {
/**
* Defines valid properties.
*/
props: MultiSelectProps;
/**
* Defines current inline state.
*/
state: MultiSelectState;
}

/**
* Custom change event.
* @see {@link MultiSelectEmits.change}
Expand Down Expand Up @@ -154,21 +169,14 @@ export interface MultiSelectPassThroughOptions {
*/
filterContainer?: MultiSelectPassThroughOptionType;
/**
* Used to pass attributes to the filter input's DOM element.
* Used to pass attributes to the InputText component.
* @see {@link InputTextPassThroughOptions}
*/
filterInput?: MultiSelectPassThroughOptionType;
filterInput?: InputTextPassThroughOptions<MultiSelectSharedPassThroughMethodOptions>;
/**
* Used to pass attributes to the filter icon's DOM element.
*/
filterIcon?: MultiSelectPassThroughOptionType;
/**
* Used to pass attributes to the close button's DOM element.
*/
closeButton?: MultiSelectPassThroughOptionType;
/**
* Used to pass attributes to the close icon's DOM element.
*/
closeIcon?: MultiSelectPassThroughOptionType;
/**
* Used to pass attributes to the wrapper's DOM element.
*/
Expand Down Expand Up @@ -255,7 +263,7 @@ export interface MultiSelectState {
focused: boolean;
/**
* Current focused item index as a number.
* @defaultvalue -1
* @defaultValue -1
*/
focusedOptionIndex: number;
/**
Expand Down Expand Up @@ -299,7 +307,7 @@ export interface MultiSelectProps {
*/
modelValue?: any;
/**
* An array of selectitems to display as the available options.
* An array of select items to display as the available options.
*/
options?: any[] | undefined;
/**
Expand Down
27 changes: 11 additions & 16 deletions components/lib/multiselect/MultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@focus="onFocus"
@blur="onBlur"
@keydown="onKeyDown"
v-bind="{ ...inputProps, ...ptm('hiddenInput') }"
v-bind="ptm('hiddenInput')"
/>
</div>
<div :class="cx('labelContainer')" v-bind="ptm('labelContainer')">
Expand Down Expand Up @@ -86,22 +86,26 @@
</template>
</Checkbox>
<div v-if="filter" :class="cx('filterContainer')" v-bind="ptm('filterContainer')">
<input
<MSInputText
ref="filterInput"
type="text"
:value="filterValue"
@vue:mounted="onFilterUpdated"
@vue:updated="onFilterUpdated"
:class="cx('filterInput')"
:placeholder="filterPlaceholder"
:invalid="invalid"
:disabled="disabled"
:variant="variant"
:unstyled="unstyled"
role="searchbox"
autocomplete="off"
:aria-owns="id + '_list'"
:aria-activedescendant="focusedOptionId"
@keydown="onFilterKeyDown"
@blur="onFilterBlur"
@input="onFilterChange"
v-bind="{ ...filterInputProps, ...ptm('filterInput') }"
v-bind="filterInputProps"
:pt="ptm('filterInput')"
/>
<slot name="filtericon" :class="cx('filterIcon')">
<component :is="filterIcon ? 'span' : 'SearchIcon'" :class="[cx('filterIcon'), filterIcon]" v-bind="ptm('filterIcon')" />
Expand All @@ -110,11 +114,6 @@
<span v-if="filter" role="status" aria-live="polite" class="p-hidden-accessible" v-bind="ptm('hiddenFilterResult')" :data-p-hidden-accessible="true">
{{ filterResultMessageText }}
</span>
<button v-ripple :class="cx('closeButton')" :aria-label="closeAriaLabel" @click="onCloseClick" type="button" v-bind="{ ...closeButtonProps, ...ptm('closeButton') }">
<slot name="closeicon" :class="cx('closeIcon')">
<component :is="closeIcon ? 'span' : 'TimesIcon'" :class="[cx('closeIcon'), closeIcon]" v-bind="ptm('closeIcon')" />
</slot>
</button>
</div>
<div :class="cx('wrapper')" :style="{ 'max-height': virtualScrollerDisabled ? scrollHeight : '' }" v-bind="ptm('wrapper')">
<VirtualScroller :ref="virtualScrollerRef" v-bind="virtualScrollerOptions" :items="visibleOptions" :style="{ height: scrollHeight }" :tabindex="-1" :disabled="virtualScrollerDisabled" :pt="ptm('virtualScroller')">
Expand Down Expand Up @@ -205,6 +204,7 @@ import SearchIcon from 'primevue/icons/search';
import SpinnerIcon from 'primevue/icons/spinner';
import TimesIcon from 'primevue/icons/times';
import TimesCircleIcon from 'primevue/icons/timescircle';
import InputText from 'primevue/inputtext';
import OverlayEventBus from 'primevue/overlayeventbus';
import Portal from 'primevue/portal';
import Ripple from 'primevue/ripple';
Expand Down Expand Up @@ -451,9 +451,6 @@ export default {
DomHandler.focus(focusableEl);
},
onCloseClick() {
this.hide(true);
},
onOptionSelect(event, option, index = -1, isFocus = false) {
if (this.disabled || this.isOptionDisabled(option)) {
return;
Expand Down Expand Up @@ -697,7 +694,7 @@ export default {
this.alignOverlay();
this.scrollInView();
this.autoFilterFocus && DomHandler.focus(this.$refs.filterInput);
this.autoFilterFocus && DomHandler.focus(this.$refs.filterInput.$el);
},
onOverlayAfterEnter() {
this.bindOutsideClickListener();
Expand Down Expand Up @@ -1085,9 +1082,6 @@ export default {
toggleAllAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria[this.allSelected ? 'selectAll' : 'unselectAll'] : undefined;
},
closeAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.close : undefined;
},
virtualScrollerDisabled() {
return !this.virtualScrollerOptions;
}
Expand All @@ -1096,6 +1090,7 @@ export default {
ripple: Ripple
},
components: {
MSInputText: InputText,
Checkbox,
VirtualScroller,
Portal,
Expand Down
11 changes: 2 additions & 9 deletions components/lib/multiselect/style/MultiSelectStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,16 @@ const classes = {
trigger: 'p-multiselect-trigger',
loadingIcon: 'p-multiselect-trigger-icon',
dropdownIcon: 'p-multiselect-trigger-icon',
panel: ({ props, instance }) => [
panel: ({ instance }) => [
'p-multiselect-panel p-component',
{
'p-ripple-disabled': instance.$primevue.config.ripple === false
}
],
header: 'p-multiselect-header',
filterContainer: 'p-multiselect-filter-container',
filterInput: ({ props, instance }) => [
'p-multiselect-filter p-inputtext p-component',
{
'p-variant-filled': props.variant ? props.variant === 'filled' : instance.$primevue.config.inputStyle === 'filled'
}
],
filterInput: 'p-multiselect-filter',
filterIcon: 'p-multiselect-filter-icon',
closeButton: 'p-multiselect-close p-link',
closeIcon: 'p-multiselect-close-icon',
wrapper: 'p-multiselect-items-wrapper',
list: 'p-multiselect-items p-component',
itemGroup: 'p-multiselect-item-group',
Expand Down

0 comments on commit 89e01ff

Please sign in to comment.