Refactor #3889 - For SpeedDial
parent
0377815bf2
commit
ccc1d4f4e0
|
@ -19,6 +19,7 @@ export declare type SpeedDialPassThroughOptionType = SpeedDialPassThroughAttribu
|
||||||
export interface SpeedDialPassThroughMethodOptions {
|
export interface SpeedDialPassThroughMethodOptions {
|
||||||
props: SpeedDialProps;
|
props: SpeedDialProps;
|
||||||
state: SpeedDialState;
|
state: SpeedDialState;
|
||||||
|
context: SpeedDialContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,6 +98,17 @@ export interface SpeedDialState {
|
||||||
focusedOptionIndex: number;
|
focusedOptionIndex: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines current options in SpeedDial component.
|
||||||
|
*/
|
||||||
|
export interface SpeedDialContext {
|
||||||
|
/**
|
||||||
|
* Current active state of menuitem as a boolean.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
active: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines tooltip options.
|
* Defines tooltip options.
|
||||||
* @see {@link SpeedDialProps.tooltipOptions}
|
* @see {@link SpeedDialProps.tooltipOptions}
|
||||||
|
|
|
@ -24,7 +24,16 @@
|
||||||
</slot>
|
</slot>
|
||||||
<ul :ref="listRef" :id="id + '_list'" class="p-speeddial-list" role="menu" @focus="onFocus" @blur="onBlur" @keydown="onKeyDown" :aria-activedescendant="focused ? focusedOptionId : undefined" tabindex="-1" v-bind="ptm('menu')">
|
<ul :ref="listRef" :id="id + '_list'" class="p-speeddial-list" role="menu" @focus="onFocus" @blur="onBlur" @keydown="onKeyDown" :aria-activedescendant="focused ? focusedOptionId : undefined" tabindex="-1" v-bind="ptm('menu')">
|
||||||
<template v-for="(item, index) of model" :key="index">
|
<template v-for="(item, index) of model" :key="index">
|
||||||
<li v-if="isItemVisible(item)" :id="`${id}_${index}`" :aria-controls="`${id}_item`" class="p-speeddial-item" :class="itemClass(`${id}_${index}`)" :style="getItemStyle(index)" role="menuitem" v-bind="ptm('menuitem')">
|
<li
|
||||||
|
v-if="isItemVisible(item)"
|
||||||
|
:id="`${id}_${index}`"
|
||||||
|
:aria-controls="`${id}_item`"
|
||||||
|
class="p-speeddial-item"
|
||||||
|
:class="itemClass(`${id}_${index}`)"
|
||||||
|
:style="getItemStyle(index)"
|
||||||
|
role="menuitem"
|
||||||
|
v-bind="getPTOptions(`${id}_${index}`, 'menuitem')"
|
||||||
|
>
|
||||||
<template v-if="!$slots.item">
|
<template v-if="!$slots.item">
|
||||||
<a
|
<a
|
||||||
v-tooltip:[tooltipOptions]="{ value: item.label, disabled: !tooltipOptions }"
|
v-tooltip:[tooltipOptions]="{ value: item.label, disabled: !tooltipOptions }"
|
||||||
|
@ -36,9 +45,9 @@
|
||||||
:target="item.target"
|
:target="item.target"
|
||||||
@click="onItemClick($event, item)"
|
@click="onItemClick($event, item)"
|
||||||
:aria-label="item.label"
|
:aria-label="item.label"
|
||||||
v-bind="ptm('action')"
|
v-bind="getPTOptions(`${id}_${index}`, 'action')"
|
||||||
>
|
>
|
||||||
<span v-if="item.icon" :class="['p-speeddial-action-icon', item.icon]" v-bind="ptm('actionIcon')"></span>
|
<span v-if="item.icon" :class="['p-speeddial-action-icon', item.icon]" v-bind="getPTOptions(`${id}_${index}`, 'actionIcon')"></span>
|
||||||
</a>
|
</a>
|
||||||
</template>
|
</template>
|
||||||
<component v-else :is="$slots.item" :item="item"></component>
|
<component v-else :is="$slots.item" :item="item"></component>
|
||||||
|
@ -168,6 +177,13 @@ export default {
|
||||||
this.unbindDocumentClickListener();
|
this.unbindDocumentClickListener();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getPTOptions(id, key) {
|
||||||
|
return this.ptm(key, {
|
||||||
|
context: {
|
||||||
|
active: this.isItemActive(id)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
onFocus(event) {
|
onFocus(event) {
|
||||||
this.focused = true;
|
this.focused = true;
|
||||||
|
|
||||||
|
@ -488,6 +504,9 @@ export default {
|
||||||
isItemVisible(item) {
|
isItemVisible(item) {
|
||||||
return typeof item.visible === 'function' ? item.visible() : item.visible !== false;
|
return typeof item.visible === 'function' ? item.visible() : item.visible !== false;
|
||||||
},
|
},
|
||||||
|
isItemActive(id) {
|
||||||
|
return id === this.focusedOptionId;
|
||||||
|
},
|
||||||
containerRef(el) {
|
containerRef(el) {
|
||||||
this.container = el;
|
this.container = el;
|
||||||
},
|
},
|
||||||
|
@ -497,7 +516,7 @@ export default {
|
||||||
itemClass(id) {
|
itemClass(id) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'p-focus': id === this.focusedOptionId
|
'p-focus': this.isItemActive(id)
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue