mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore(Tab): using Vue built-in stringifyStyle (#11914)
* chore(Tab): using Vue built-in stringifyStyle * fix(Tab): failed to normalize style
This commit is contained in:
parent
53a108ec7e
commit
b2d49a35d9
@ -46,7 +46,8 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vant/popperjs": "^1.3.0",
|
"@vant/popperjs": "^1.3.0",
|
||||||
"@vant/use": "^1.5.1"
|
"@vant/use": "^1.5.1",
|
||||||
|
"@vue/shared": "^3.0.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"vue": "^3.0.0"
|
"vue": "^3.0.0"
|
||||||
|
@ -4,14 +4,17 @@ import {
|
|||||||
provide,
|
provide,
|
||||||
computed,
|
computed,
|
||||||
nextTick,
|
nextTick,
|
||||||
defineComponent,
|
watchEffect,
|
||||||
getCurrentInstance,
|
|
||||||
normalizeClass,
|
normalizeClass,
|
||||||
normalizeStyle,
|
normalizeStyle,
|
||||||
|
defineComponent,
|
||||||
|
getCurrentInstance,
|
||||||
type PropType,
|
type PropType,
|
||||||
type CSSProperties,
|
type CSSProperties,
|
||||||
type ExtractPropTypes,
|
type ExtractPropTypes,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
// eslint-disable-next-line vue/prefer-import-from-vue
|
||||||
|
import { stringifyStyle } from '@vue/shared';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import {
|
import {
|
||||||
@ -22,7 +25,6 @@ import {
|
|||||||
numericProp,
|
numericProp,
|
||||||
createNamespace,
|
createNamespace,
|
||||||
ComponentInstance,
|
ComponentInstance,
|
||||||
isObject,
|
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { TABS_KEY } from '../tabs/Tabs';
|
import { TABS_KEY } from '../tabs/Tabs';
|
||||||
|
|
||||||
@ -93,23 +95,16 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// see: https://github.com/vant-ui/vant/issues/11763
|
// see: https://github.com/vant-ui/vant/issues/11763
|
||||||
const parserClass = ref('');
|
const parsedClass = ref('');
|
||||||
const parserStyle = ref('');
|
const parsedStyle = ref<string | undefined>('');
|
||||||
watch(
|
watchEffect(() => {
|
||||||
[() => props.titleClass, () => props.titleStyle],
|
const { titleClass, titleStyle } = props;
|
||||||
([newClass, newStyle]) => {
|
parsedClass.value = titleClass ? normalizeClass(titleClass) : '';
|
||||||
parserClass.value = normalizeClass(newClass);
|
parsedStyle.value =
|
||||||
const style = normalizeStyle(newStyle);
|
titleStyle && typeof titleStyle !== 'string'
|
||||||
if (isObject(style)) {
|
? stringifyStyle(normalizeStyle(titleStyle))
|
||||||
parserStyle.value = Object.entries(style)
|
: titleStyle;
|
||||||
.map(([key, val]) => `${key}:${val}; `)
|
});
|
||||||
.join('');
|
|
||||||
} else {
|
|
||||||
parserStyle.value = style ?? '';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderTitle = (
|
const renderTitle = (
|
||||||
onClickTab: (
|
onClickTab: (
|
||||||
@ -123,8 +118,8 @@ export default defineComponent({
|
|||||||
v-slots={{ title: slots.title }}
|
v-slots={{ title: slots.title }}
|
||||||
id={`${parent.id}-${index.value}`}
|
id={`${parent.id}-${index.value}`}
|
||||||
ref={parent.setTitleRefs(index.value)}
|
ref={parent.setTitleRefs(index.value)}
|
||||||
style={parserStyle.value}
|
style={parsedStyle.value}
|
||||||
class={parserClass.value}
|
class={parsedClass.value}
|
||||||
isActive={active.value}
|
isActive={active.value}
|
||||||
controls={id}
|
controls={id}
|
||||||
scrollable={parent.scrollable.value}
|
scrollable={parent.scrollable.value}
|
||||||
|
@ -189,13 +189,18 @@ test('should change title style when using title-style prop', async () => {
|
|||||||
<Tab title="title1" titleStyle="color: red;">
|
<Tab title="title1" titleStyle="color: red;">
|
||||||
Text
|
Text
|
||||||
</Tab>
|
</Tab>
|
||||||
|
<Tab title="title1" titleStyle={{ color: 'blue' }}>
|
||||||
|
Text
|
||||||
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await later();
|
await later();
|
||||||
expect(wrapper.find('.van-tab').style.color).toEqual('red');
|
const tabs = wrapper.findAll('.van-tab');
|
||||||
|
expect(tabs.at(0)!.style.color).toEqual('red');
|
||||||
|
expect(tabs.at(1)!.style.color).toEqual('blue');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should allot to hide bottom border by border prop', async () => {
|
test('should allot to hide bottom border by border prop', async () => {
|
||||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -62,6 +62,9 @@ importers:
|
|||||||
'@vant/use':
|
'@vant/use':
|
||||||
specifier: ^1.5.1
|
specifier: ^1.5.1
|
||||||
version: link:../vant-use
|
version: link:../vant-use
|
||||||
|
'@vue/shared':
|
||||||
|
specifier: ^3.0.0
|
||||||
|
version: 3.3.4
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/jest':
|
'@types/jest':
|
||||||
specifier: ^29.5.1
|
specifier: ^29.5.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user