Refactor #6647 - For Tabs
parent
acabcaec8b
commit
fcfcea766e
|
@ -39,18 +39,20 @@
|
||||||
import { findSingle, getHeight, getOffset, getOuterHeight, getOuterWidth, getWidth } from '@primeuix/utils/dom';
|
import { findSingle, getHeight, getOffset, getOuterHeight, getOuterWidth, getWidth } from '@primeuix/utils/dom';
|
||||||
import ChevronLeftIcon from '@primevue/icons/chevronleft';
|
import ChevronLeftIcon from '@primevue/icons/chevronleft';
|
||||||
import ChevronRightIcon from '@primevue/icons/chevronright';
|
import ChevronRightIcon from '@primevue/icons/chevronright';
|
||||||
import BaseTabList from './BaseTabList.vue';
|
|
||||||
import Ripple from 'primevue/ripple';
|
import Ripple from 'primevue/ripple';
|
||||||
|
import BaseTabList from './BaseTabList.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'TabList',
|
name: 'TabList',
|
||||||
extends: BaseTabList,
|
extends: BaseTabList,
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
inject: ['$pcTabs'],
|
inject: ['$pcTabs'],
|
||||||
|
mutationObserver: null,
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isPrevButtonEnabled: false,
|
isPrevButtonEnabled: false,
|
||||||
isNextButtonEnabled: true
|
isNextButtonEnabled: true,
|
||||||
|
isRTL: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
resizeObserver: undefined,
|
resizeObserver: undefined,
|
||||||
|
@ -74,14 +76,39 @@ export default {
|
||||||
this.updateButtonState();
|
this.updateButtonState();
|
||||||
this.bindResizeObserver();
|
this.bindResizeObserver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateDirection();
|
||||||
|
this.observeDirectionChanges();
|
||||||
},
|
},
|
||||||
updated() {
|
updated() {
|
||||||
this.showNavigators && this.updateButtonState();
|
this.showNavigators && this.updateButtonState();
|
||||||
},
|
},
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
this.unbindResizeObserver();
|
this.unbindResizeObserver();
|
||||||
|
|
||||||
|
if (this.mutationObserver) {
|
||||||
|
this.mutationObserver.disconnect();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
updateDirection() {
|
||||||
|
if (document) {
|
||||||
|
const isHtmlRtl = document.documentElement.getAttribute('dir') === 'rtl';
|
||||||
|
const isBodyRtl = document.body.getAttribute('dir') === 'rtl';
|
||||||
|
|
||||||
|
this.isRTL = isHtmlRtl || isBodyRtl || this.$el.closest('[dir="rtl"]');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
observeDirectionChanges() {
|
||||||
|
const targetNode = document.documentElement;
|
||||||
|
const config = { attributes: true, attributeFilter: ['dir'] };
|
||||||
|
|
||||||
|
this.mutationObserver = new MutationObserver(() => {
|
||||||
|
this.updateDirection();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.mutationObserver.observe(targetNode, config);
|
||||||
|
},
|
||||||
onScroll(event) {
|
onScroll(event) {
|
||||||
this.showNavigators && this.updateButtonState();
|
this.showNavigators && this.updateButtonState();
|
||||||
|
|
||||||
|
@ -90,15 +117,28 @@ export default {
|
||||||
onPrevButtonClick() {
|
onPrevButtonClick() {
|
||||||
const content = this.$refs.content;
|
const content = this.$refs.content;
|
||||||
const width = getWidth(content);
|
const width = getWidth(content);
|
||||||
const pos = content.scrollLeft - width;
|
let pos;
|
||||||
|
|
||||||
|
if (this.isRTL) {
|
||||||
|
pos = content.scrollLeft + width;
|
||||||
|
} else {
|
||||||
|
pos = content.scrollLeft - width;
|
||||||
|
}
|
||||||
|
|
||||||
content.scrollLeft = pos <= 0 ? 0 : pos;
|
content.scrollLeft = pos <= 0 ? 0 : pos;
|
||||||
},
|
},
|
||||||
onNextButtonClick() {
|
onNextButtonClick() {
|
||||||
const content = this.$refs.content;
|
const content = this.$refs.content;
|
||||||
const width = getWidth(content) - this.getVisibleButtonWidths();
|
const width = getWidth(content) - this.getVisibleButtonWidths();
|
||||||
const pos = content.scrollLeft + width;
|
let pos, lastPos;
|
||||||
const lastPos = content.scrollWidth - width;
|
|
||||||
|
if (this.isRTL) {
|
||||||
|
pos = content.scrollLeft - width;
|
||||||
|
lastPos = content.scrollWidth + width;
|
||||||
|
} else {
|
||||||
|
pos = content.scrollLeft + width;
|
||||||
|
lastPos = content.scrollWidth - width;
|
||||||
|
}
|
||||||
|
|
||||||
content.scrollLeft = pos >= lastPos ? lastPos : pos;
|
content.scrollLeft = pos >= lastPos ? lastPos : pos;
|
||||||
},
|
},
|
||||||
|
|
|
@ -44,7 +44,7 @@ const theme = ({ dt }) => `
|
||||||
all: unset;
|
all: unset;
|
||||||
position: absolute !important;
|
position: absolute !important;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
top: 0;
|
inset-block-start: 0;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -71,13 +71,19 @@ const theme = ({ dt }) => `
|
||||||
}
|
}
|
||||||
|
|
||||||
.p-tablist-prev-button {
|
.p-tablist-prev-button {
|
||||||
left: 0;
|
inset-inline-start: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.p-tablist-next-button {
|
.p-tablist-next-button {
|
||||||
right: 0;
|
inset-inline-end: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.p-tablist-prev-button:dir(rtl),
|
||||||
|
.p-tablist-next-button:dir(rtl) {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.p-tab {
|
.p-tab {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -132,7 +138,7 @@ const theme = ({ dt }) => `
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
display: block;
|
display: block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: ${dt('tabs.active.bar.bottom')};
|
inset-block-end: ${dt('tabs.active.bar.bottom')};
|
||||||
height: ${dt('tabs.active.bar.height')};
|
height: ${dt('tabs.active.bar.height')};
|
||||||
background: ${dt('tabs.active.bar.background')};
|
background: ${dt('tabs.active.bar.background')};
|
||||||
transition: 250ms cubic-bezier(0.35, 0, 0.25, 1);
|
transition: 250ms cubic-bezier(0.35, 0, 0.25, 1);
|
||||||
|
|
Loading…
Reference in New Issue