Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tabs): fix content adaptive problem when direction is rtl
Browse files Browse the repository at this point in the history
jadelike-wine committed Jan 9, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 39b69d5 commit 509e9d6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/web-vue/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import {
reactive,
ref,
toRefs,
onMounted,
} from 'vue';
import type { Direction, Size } from '../_utils/constant';
import type {
@@ -295,6 +296,19 @@ export default defineComponent({
emit('delete', key, ev);
};

// 用于存储组件对应的 DOM 元素
const tabsDOM = ref(null);
// 判断是否是 rtl 方向
const isRTL = ref(false);

// 在组件挂载后获取 DOM 元素并判断方向
onMounted(() => {
if (tabsDOM.value) {
const style = window.getComputedStyle(tabsDOM.value);
isRTL.value = style.direction === 'rtl';
}
});

const renderContent = () => {
return (
<div
@@ -312,7 +326,12 @@ export default defineComponent({
[`${prefixCls}-content-animation`]: props.animation,
},
]}
style={{ marginLeft: `-${activeIndex.value * 100}%` }}
style={{
marginLeft: isRTL.value ? 'auto' : `-${activeIndex.value * 100}%`,
marginRight: isRTL.value
? `-${activeIndex.value * 100}%`
: 'auto',
}}
>
{children.value}
</div>
@@ -335,7 +354,7 @@ export default defineComponent({
children.value = slots.default?.();

return (
<div class={cls.value}>
<div ref={tabsDOM} class={cls.value}>
{mergedPosition.value === 'bottom' && renderContent()}
<TabsNav
v-slots={{ extra: slots.extra }}

0 comments on commit 509e9d6

Please sign in to comment.