Refactor #3922 - For AutoComplete
parent
f9d732a403
commit
d8703c4cae
|
@ -20,6 +20,7 @@ export declare type AutoCompletePassThroughOptionType = AutoCompletePassThroughA
|
||||||
export interface AutoCompletePassThroughMethodOptions {
|
export interface AutoCompletePassThroughMethodOptions {
|
||||||
props: AutoCompleteProps;
|
props: AutoCompleteProps;
|
||||||
state: AutoCompleteState;
|
state: AutoCompleteState;
|
||||||
|
context: AutoCompleteContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,10 +174,55 @@ export interface AutoCompletePassThroughAttributes {
|
||||||
*/
|
*/
|
||||||
export interface AutoCompleteState {
|
export interface AutoCompleteState {
|
||||||
/**
|
/**
|
||||||
* Current collapsed state as a boolean.
|
* Current id state as a string.
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
|
/**
|
||||||
|
* Current focused state as a boolean.
|
||||||
* @defaultValue false
|
* @defaultValue false
|
||||||
*/
|
*/
|
||||||
d_collapsed: boolean;
|
focused: boolean;
|
||||||
|
/**
|
||||||
|
* Current focused item index as a number.
|
||||||
|
* @defaultvalue -1
|
||||||
|
*/
|
||||||
|
focusedOptionIndex: number;
|
||||||
|
/**
|
||||||
|
* Current focused item index as a number.
|
||||||
|
* @defaultvalue -1
|
||||||
|
*/
|
||||||
|
focusedMultipleOptionIndex: number;
|
||||||
|
/**
|
||||||
|
* Current overlay visible state as a boolean.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
overlayVisible: boolean;
|
||||||
|
/**
|
||||||
|
* Current search state as a boolean.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
searching: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines current options in AutoComplete component.
|
||||||
|
*/
|
||||||
|
export interface AutoCompleteContext {
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
</Button>
|
</Button>
|
||||||
<span role="status" aria-live="polite" class="p-hidden-accessible" v-bind="ptm('searchResultMessage')">
|
<span role="status" aria-live="polite" class="p-hidden-accessible" v-bind="ptm('hiddenSearchResult')">
|
||||||
{{ searchResultMessageText }}
|
{{ searchResultMessageText }}
|
||||||
</span>
|
</span>
|
||||||
<Portal :appendTo="appendTo">
|
<Portal :appendTo="appendTo">
|
||||||
|
@ -141,7 +141,7 @@
|
||||||
:aria-posinset="getAriaPosInset(getOptionIndex(i, getItemOptions))"
|
:aria-posinset="getAriaPosInset(getOptionIndex(i, getItemOptions))"
|
||||||
@click="onOptionSelect($event, option)"
|
@click="onOptionSelect($event, option)"
|
||||||
@mousemove="onOptionMouseMove($event, getOptionIndex(i, getItemOptions))"
|
@mousemove="onOptionMouseMove($event, getOptionIndex(i, getItemOptions))"
|
||||||
v-bind="ptm('item')"
|
v-bind="getPTOptions(option, getItemOptions, i, 'item')"
|
||||||
>
|
>
|
||||||
<slot v-if="$slots.option" name="option" :option="option" :index="getOptionIndex(i, getItemOptions)">{{ getOptionLabel(option) }}</slot>
|
<slot v-if="$slots.option" name="option" :option="option" :index="getOptionIndex(i, getItemOptions)">{{ getOptionLabel(option) }}</slot>
|
||||||
<slot v-else name="item" :item="option" :index="getOptionIndex(i, getItemOptions)">{{ getOptionLabel(option) }}</slot>
|
<slot v-else name="item" :item="option" :index="getOptionIndex(i, getItemOptions)">{{ getOptionLabel(option) }}</slot>
|
||||||
|
@ -158,7 +158,7 @@
|
||||||
</template>
|
</template>
|
||||||
</VirtualScroller>
|
</VirtualScroller>
|
||||||
<slot name="footer" :value="modelValue" :suggestions="visibleOptions"></slot>
|
<slot name="footer" :value="modelValue" :suggestions="visibleOptions"></slot>
|
||||||
<span role="status" aria-live="polite" class="p-hidden-accessible" v-bind="ptm('selectedMessage')">
|
<span role="status" aria-live="polite" class="p-hidden-accessible" v-bind="ptm('hiddenSelectedMessage')">
|
||||||
{{ selectedMessageText }}
|
{{ selectedMessageText }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -409,6 +409,15 @@ export default {
|
||||||
getOptionRenderKey(option, index) {
|
getOptionRenderKey(option, index) {
|
||||||
return (this.dataKey ? ObjectUtils.resolveFieldData(option, this.dataKey) : this.getOptionLabel(option)) + '_' + index;
|
return (this.dataKey ? ObjectUtils.resolveFieldData(option, this.dataKey) : this.getOptionLabel(option)) + '_' + index;
|
||||||
},
|
},
|
||||||
|
getPTOptions(option, itemOptions, index, key) {
|
||||||
|
return this.ptm(key, {
|
||||||
|
context: {
|
||||||
|
selected: this.isSelected(option),
|
||||||
|
focused: this.focusedOptionIndex === this.getOptionIndex(index, itemOptions),
|
||||||
|
disabled: this.isOptionDisabled(option)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
isOptionDisabled(option) {
|
isOptionDisabled(option) {
|
||||||
return this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : false;
|
return this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : false;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue