Skip to content

Commit cc03640

Browse files
authored
feat(TreeSelect): add className option (youzan#4671)
1 parent 514a279 commit cc03640

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

src/tree-select/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ In every tree object, `text` property defines `id` stands for the unique key whi
145145
info: 3,
146146
// Whether to show red dot
147147
dot: true,
148+
// ClassName of parent node
149+
className: 'my-class',
148150
// leaves of this parent node
149151
children: [
150152
{

src/tree-select/README.zh-CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export default {
151151
info: 3,
152152
// 是否在导航名称右上角显示小红点
153153
dot: true,
154+
// 导航节点额外类名
155+
className: 'my-class',
154156
// 该导航下所有的可选项
155157
children: [
156158
{

src/tree-select/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type TreeSelectItem = {
1313
dot?: boolean;
1414
info?: string | number;
1515
disabled?: boolean;
16+
className?: any;
1617
children: TreeSelectChildren[];
1718
};
1819

@@ -62,7 +63,7 @@ function TreeSelect(
6263
info={item.info}
6364
title={item.text}
6465
disabled={item.disabled}
65-
class={bem('nav-item')}
66+
class={[bem('nav-item'), item.className]}
6667
/>
6768
));
6869

src/tree-select/test/index.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ test('max prop', () => {
262262
data() {
263263
return {
264264
activeId: [],
265-
mainActiveIndex: 0,
266265
items: [
267266
{
268267
text: 'group1',
@@ -278,3 +277,21 @@ test('max prop', () => {
278277
items.at(1).trigger('click');
279278
expect(wrapper.vm.activeId).toEqual([mockItem.id]);
280279
});
280+
281+
test('className of nav', () => {
282+
const wrapper = mount(TreeSelect, {
283+
propsData: {
284+
mainActiveIndex: 0,
285+
items: [
286+
{
287+
text: 'group1',
288+
className: 'my-class',
289+
children: []
290+
}
291+
]
292+
}
293+
});
294+
295+
const items = wrapper.findAll('.van-tree-select__nav-item');
296+
expect(items.at(0).element.classList.contains('my-class')).toBeTruthy();
297+
});

0 commit comments

Comments
 (0)