Fixed #3794 - TabView: new passthrough(pt) property implementation
parent
0880120766
commit
b63bc4db2f
|
@ -52,6 +52,12 @@ const TabPanelProps = [
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: 'null',
|
default: 'null',
|
||||||
description: 'Whether the tab is disabled.'
|
description: 'Whether the tab is disabled.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'pt',
|
||||||
|
type: 'any',
|
||||||
|
default: 'null',
|
||||||
|
description: 'Uses to pass attributes to DOM elements inside the component.'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,12 @@ const TabViewProps = [
|
||||||
type: 'any',
|
type: 'any',
|
||||||
default: 'null',
|
default: 'null',
|
||||||
description: 'Uses to pass all properties of the HTMLButtonElement to the next button.'
|
description: 'Uses to pass all properties of the HTMLButtonElement to the next button.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'pt',
|
||||||
|
type: 'any',
|
||||||
|
default: 'null',
|
||||||
|
description: 'Uses to pass attributes to DOM elements inside the component.'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -78,11 +84,27 @@ const TabViewEvents = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const TabViewSlots = [
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
description: 'Default slot to detect TabPanel components.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'previcon',
|
||||||
|
description: 'Previous button icon template for the scrollable component.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'nexticon',
|
||||||
|
description: 'Next button icon template for the scrollable component.'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
tabview: {
|
tabview: {
|
||||||
name: 'TabView',
|
name: 'TabView',
|
||||||
description: 'TabView is a container component to group content with tabs.',
|
description: 'TabView is a container component to group content with tabs.',
|
||||||
props: TabViewProps,
|
props: TabViewProps,
|
||||||
event: TabViewEvents
|
event: TabViewEvents,
|
||||||
|
slots: TabViewSlots
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,50 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { AnchorHTMLAttributes, HTMLAttributes, LiHTMLAttributes, VNode } from 'vue';
|
import { AnchorHTMLAttributes, HTMLAttributes, LiHTMLAttributes, VNode } from 'vue';
|
||||||
|
import { TabViewPassThroughOptions } from '../tabview';
|
||||||
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
||||||
|
|
||||||
|
export declare type TabPanelPassThroughOptionType = TabPanelPassThroughAttributes | ((options: TabPanelPassThroughMethodOptions) => TabPanelPassThroughAttributes) | null | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough(pt) option method.
|
||||||
|
*/
|
||||||
|
export interface TabPanelPassThroughMethodOptions {
|
||||||
|
props: TabPanelProps;
|
||||||
|
parent: TabViewPassThroughOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough(pt) options.
|
||||||
|
* @see {@link TabPanelProps.pt}
|
||||||
|
*/
|
||||||
|
export interface TabPanelPassThroughOptions {
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the root's DOM element.
|
||||||
|
*/
|
||||||
|
root?: TabPanelPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the header's DOM element.
|
||||||
|
*/
|
||||||
|
header?: TabPanelPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the header action's DOM element.
|
||||||
|
*/
|
||||||
|
headeraction?: TabPanelPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the title's DOM element.
|
||||||
|
*/
|
||||||
|
headertitle?: TabPanelPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the list's DOM element.
|
||||||
|
*/
|
||||||
|
content?: TabPanelPassThroughOptionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TabPanelPassThroughAttributes {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines valid properties in TabPanel component.
|
* Defines valid properties in TabPanel component.
|
||||||
*/
|
*/
|
||||||
|
@ -20,30 +62,37 @@ export interface TabPanelProps {
|
||||||
header?: string | undefined;
|
header?: string | undefined;
|
||||||
/**
|
/**
|
||||||
* Inline style of the tab header.
|
* Inline style of the tab header.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
headerStyle?: any;
|
headerStyle?: any;
|
||||||
/**
|
/**
|
||||||
* Style class of the tab header.
|
* Style class of the tab header.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
headerClass?: any;
|
headerClass?: any;
|
||||||
/**
|
/**
|
||||||
* Uses to pass all properties of the HTMLLiElement to the tab header.
|
* Uses to pass all properties of the HTMLLiElement to the tab header.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
headerProps?: LiHTMLAttributes | undefined;
|
headerProps?: LiHTMLAttributes | undefined;
|
||||||
/**
|
/**
|
||||||
* Uses to pass all properties of the HTMLAnchorElement to the focusable anchor element inside the tab header.
|
* Uses to pass all properties of the HTMLAnchorElement to the focusable anchor element inside the tab header.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
headerActionProps?: AnchorHTMLAttributes | undefined;
|
headerActionProps?: AnchorHTMLAttributes | undefined;
|
||||||
/**
|
/**
|
||||||
* Inline style of the tab content.
|
* Inline style of the tab content.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
contentStyle?: any;
|
contentStyle?: any;
|
||||||
/**
|
/**
|
||||||
* Style class of the tab content.
|
* Style class of the tab content.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
contentClass?: any;
|
contentClass?: any;
|
||||||
/**
|
/**
|
||||||
* Uses to pass all properties of the HTMLDivElement to the tab content.
|
* Uses to pass all properties of the HTMLDivElement to the tab content.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
contentProps?: HTMLAttributes | undefined;
|
contentProps?: HTMLAttributes | undefined;
|
||||||
/**
|
/**
|
||||||
|
@ -51,6 +100,11 @@ export interface TabPanelProps {
|
||||||
* @defaultValue false
|
* @defaultValue false
|
||||||
*/
|
*/
|
||||||
disabled?: boolean | undefined;
|
disabled?: boolean | undefined;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to DOM elements inside the component.
|
||||||
|
* @type {TabPanelPassThroughOptions}
|
||||||
|
*/
|
||||||
|
pt?: TabPanelPassThroughOptions;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Defines valid slots in TabPanel slots.
|
* Defines valid slots in TabPanel slots.
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import ComponentBase from 'primevue/base';
|
||||||
export default {
|
export default {
|
||||||
name: 'TabPanel',
|
name: 'TabPanel',
|
||||||
|
extends: ComponentBase,
|
||||||
props: {
|
props: {
|
||||||
header: null,
|
header: null,
|
||||||
headerStyle: null,
|
headerStyle: null,
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
import { ButtonHTMLAttributes, VNode } from 'vue';
|
import { ButtonHTMLAttributes, VNode } from 'vue';
|
||||||
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
||||||
|
|
||||||
|
export declare type TabViewPassThroughOptionType = TabViewPassThroughAttributes | ((options: { props: TabViewProps; state: TabViewState }) => TabViewPassThroughAttributes) | null | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom tab change event.
|
* Custom tab change event.
|
||||||
* @see {@link TabViewEmits['tab-change']}
|
* @see {@link TabViewEmits['tab-change']}
|
||||||
|
@ -32,6 +34,86 @@ export interface TabViewChangeEvent {
|
||||||
*/
|
*/
|
||||||
export interface TabViewClickEvent extends TabViewChangeEvent {}
|
export interface TabViewClickEvent extends TabViewChangeEvent {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough(pt) options.
|
||||||
|
* @see {@link TabViewProps.pt}
|
||||||
|
*/
|
||||||
|
export interface TabViewPassThroughOptions {
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the root's DOM element.
|
||||||
|
*/
|
||||||
|
root?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the nav container's DOM element.
|
||||||
|
*/
|
||||||
|
navcontainer?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the nav content's DOM element.
|
||||||
|
*/
|
||||||
|
navcontent?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the list's DOM element.
|
||||||
|
*/
|
||||||
|
nav?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the list items' DOM element.
|
||||||
|
*/
|
||||||
|
tabheader?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the inkbar's DOM element.
|
||||||
|
*/
|
||||||
|
inkbar?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the previous button's DOM element.
|
||||||
|
*/
|
||||||
|
prevbutton?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the previous button icon's DOM element.
|
||||||
|
*/
|
||||||
|
previcon?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the nex button's DOM element.
|
||||||
|
*/
|
||||||
|
nextbutton?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the next button icon's DOM element.
|
||||||
|
*/
|
||||||
|
nexticon?: TabViewPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the panel's DOM element.
|
||||||
|
*/
|
||||||
|
panelcontent?: TabViewPassThroughOptionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough attributes for each DOM elements
|
||||||
|
*/
|
||||||
|
export interface TabViewPassThroughAttributes {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines current inline state in TabView component.
|
||||||
|
*/
|
||||||
|
export interface TabViewState {
|
||||||
|
/**
|
||||||
|
* Current collapsed state as a boolean.
|
||||||
|
*/
|
||||||
|
d_activeIndex: number;
|
||||||
|
/**
|
||||||
|
* Unique id for the TabView component.
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
|
/**
|
||||||
|
* Current state of previous button.
|
||||||
|
*/
|
||||||
|
isPrevButtonDisabled: boolean;
|
||||||
|
/**
|
||||||
|
* Current state of the next button.
|
||||||
|
*/
|
||||||
|
isNextButtonDisabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines valid properties in TabView component.
|
* Defines valid properties in TabView component.
|
||||||
*/
|
*/
|
||||||
|
@ -63,12 +145,19 @@ export interface TabViewProps {
|
||||||
selectOnFocus?: boolean | undefined;
|
selectOnFocus?: boolean | undefined;
|
||||||
/**
|
/**
|
||||||
* Uses to pass all properties of the HTMLButtonElement to the previous button.
|
* Uses to pass all properties of the HTMLButtonElement to the previous button.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
previousButtonProps?: ButtonHTMLAttributes | undefined;
|
previousButtonProps?: ButtonHTMLAttributes | undefined;
|
||||||
/**
|
/**
|
||||||
* Uses to pass all properties of the HTMLButtonElement to the next button.
|
* Uses to pass all properties of the HTMLButtonElement to the next button.
|
||||||
|
* @deprecated since v3.26.0. Use 'pt' property instead.
|
||||||
*/
|
*/
|
||||||
nextButtonProps?: ButtonHTMLAttributes | undefined;
|
nextButtonProps?: ButtonHTMLAttributes | undefined;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to DOM elements inside the component.
|
||||||
|
* @type {TabViewPassThroughOptions}
|
||||||
|
*/
|
||||||
|
pt?: TabViewPassThroughOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,6 +168,14 @@ export interface TabViewSlots {
|
||||||
* Default slot to detect TabPanel components.
|
* Default slot to detect TabPanel components.
|
||||||
*/
|
*/
|
||||||
default(): VNode[];
|
default(): VNode[];
|
||||||
|
/**
|
||||||
|
* Previous button icon template for the scrollable component.
|
||||||
|
*/
|
||||||
|
previcon(): VNode[];
|
||||||
|
/**
|
||||||
|
* Next button icon template for the scrollable component.
|
||||||
|
*/
|
||||||
|
nexticon(): VNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="contentClasses">
|
<div :class="contentClasses" v-bind="ptm('root')">
|
||||||
<div class="p-tabview-nav-container">
|
<div class="p-tabview-nav-container" v-bind="ptm('navcontainer')">
|
||||||
<button
|
<button
|
||||||
v-if="scrollable && !isPrevButtonDisabled"
|
v-if="scrollable && !isPrevButtonDisabled"
|
||||||
ref="prevBtn"
|
ref="prevBtn"
|
||||||
|
@ -10,13 +10,23 @@
|
||||||
:tabindex="tabindex"
|
:tabindex="tabindex"
|
||||||
:aria-label="prevButtonAriaLabel"
|
:aria-label="prevButtonAriaLabel"
|
||||||
@click="onPrevButtonClick"
|
@click="onPrevButtonClick"
|
||||||
v-bind="previousButtonProps"
|
v-bind="{ ...previousButtonProps, ...ptm('prevbutton') }"
|
||||||
>
|
>
|
||||||
<span class="pi pi-chevron-left" aria-hidden="true"></span>
|
<slot name="previcon">
|
||||||
|
<span class="pi pi-chevron-left" aria-hidden="true" v-bind="ptm('previcon')"></span>
|
||||||
|
</slot>
|
||||||
</button>
|
</button>
|
||||||
<div ref="content" class="p-tabview-nav-content" @scroll="onScroll">
|
<div ref="content" class="p-tabview-nav-content" @scroll="onScroll" v-bind="ptm('navcontent')">
|
||||||
<ul ref="nav" class="p-tabview-nav" role="tablist">
|
<ul ref="nav" class="p-tabview-nav" role="tablist" v-bind="ptm('nav')">
|
||||||
<li v-for="(tab, i) of tabs" :key="getKey(tab, i)" :style="getTabProp(tab, 'headerStyle')" :class="getTabHeaderClass(tab, i)" role="presentation" :data-index="i" v-bind="getTabProp(tab, 'headerProps')">
|
<li
|
||||||
|
v-for="(tab, i) of tabs"
|
||||||
|
:key="getKey(tab, i)"
|
||||||
|
:style="getTabProp(tab, 'headerStyle')"
|
||||||
|
:class="getTabHeaderClass(tab, i)"
|
||||||
|
role="presentation"
|
||||||
|
:data-index="i"
|
||||||
|
v-bind="{ ...getTabProp(tab, 'headerProps'), ...getTabPT(tab, 'root'), ...getTabPT(tab, 'header') }"
|
||||||
|
>
|
||||||
<a
|
<a
|
||||||
:id="getTabHeaderActionId(i)"
|
:id="getTabHeaderActionId(i)"
|
||||||
v-ripple
|
v-ripple
|
||||||
|
@ -28,13 +38,13 @@
|
||||||
:aria-controls="getTabContentId(i)"
|
:aria-controls="getTabContentId(i)"
|
||||||
@click="onTabClick($event, tab, i)"
|
@click="onTabClick($event, tab, i)"
|
||||||
@keydown="onTabKeyDown($event, tab, i)"
|
@keydown="onTabKeyDown($event, tab, i)"
|
||||||
v-bind="getTabProp(tab, 'headerActionProps')"
|
v-bind="{ ...getTabProp(tab, 'headerActionProps'), ...getTabPT(tab, 'headeraction') }"
|
||||||
>
|
>
|
||||||
<span v-if="tab.props && tab.props.header" class="p-tabview-title">{{ tab.props.header }}</span>
|
<span v-if="tab.props && tab.props.header" class="p-tabview-title" v-bind="getTabPT(tab, 'headertitle')">{{ tab.props.header }}</span>
|
||||||
<component v-if="tab.children && tab.children.header" :is="tab.children.header"></component>
|
<component v-if="tab.children && tab.children.header" :is="tab.children.header"></component>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li ref="inkbar" class="p-tabview-ink-bar" role="presentation" aria-hidden="true"></li>
|
<li ref="inkbar" class="p-tabview-ink-bar" role="presentation" aria-hidden="true" v-bind="ptm('inkbar')"></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
@ -46,12 +56,14 @@
|
||||||
:tabindex="tabindex"
|
:tabindex="tabindex"
|
||||||
:aria-label="nextButtonAriaLabel"
|
:aria-label="nextButtonAriaLabel"
|
||||||
@click="onNextButtonClick"
|
@click="onNextButtonClick"
|
||||||
v-bind="nextButtonProps"
|
v-bind="{ ...nextButtonProps, ...ptm('nextbutton') }"
|
||||||
>
|
>
|
||||||
<span class="pi pi-chevron-right" aria-hidden="true"></span>
|
<slot name="nexticon">
|
||||||
|
<span class="pi pi-chevron-right" aria-hidden="true" v-bind="ptm('nexticon')"></span>
|
||||||
|
</slot>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-tabview-panels">
|
<div class="p-tabview-panels" v-bind="ptm('panelcontent')">
|
||||||
<template v-for="(tab, i) of tabs" :key="getKey(tab, i)">
|
<template v-for="(tab, i) of tabs" :key="getKey(tab, i)">
|
||||||
<div
|
<div
|
||||||
v-if="lazy ? isTabActive(i) : true"
|
v-if="lazy ? isTabActive(i) : true"
|
||||||
|
@ -60,7 +72,7 @@
|
||||||
:class="getTabContentClass(tab)"
|
:class="getTabContentClass(tab)"
|
||||||
role="tabpanel"
|
role="tabpanel"
|
||||||
:aria-labelledby="getTabHeaderActionId(i)"
|
:aria-labelledby="getTabHeaderActionId(i)"
|
||||||
v-bind="getTabProp(tab, 'contentProps')"
|
v-bind="{ ...getTabProp(tab, 'contentProps'), ...getTabPT(tab, 'root'), ...getTabPT(tab, 'content') }"
|
||||||
>
|
>
|
||||||
<component :is="tab"></component>
|
<component :is="tab"></component>
|
||||||
</div>
|
</div>
|
||||||
|
@ -70,11 +82,13 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import ComponentBase from 'primevue/base';
|
||||||
import Ripple from 'primevue/ripple';
|
import Ripple from 'primevue/ripple';
|
||||||
import { DomHandler, UniqueComponentId } from 'primevue/utils';
|
import { DomHandler, UniqueComponentId } from 'primevue/utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'TabView',
|
name: 'TabView',
|
||||||
|
extends: ComponentBase,
|
||||||
emits: ['update:activeIndex', 'tab-change', 'tab-click'],
|
emits: ['update:activeIndex', 'tab-change', 'tab-click'],
|
||||||
props: {
|
props: {
|
||||||
activeIndex: {
|
activeIndex: {
|
||||||
|
@ -152,6 +166,15 @@ export default {
|
||||||
getTabContentId(index) {
|
getTabContentId(index) {
|
||||||
return `${this.id}_${index}_content`;
|
return `${this.id}_${index}_content`;
|
||||||
},
|
},
|
||||||
|
getTabPT(tab, key) {
|
||||||
|
return this.ptmo(this.getTabProp(tab, 'pt'), key, {
|
||||||
|
props: tab.props,
|
||||||
|
parent: {
|
||||||
|
props: this.$props,
|
||||||
|
state: this.$data
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
onScroll(event) {
|
onScroll(event) {
|
||||||
this.scrollable && this.updateButtonState();
|
this.scrollable && this.updateButtonState();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue