Skip to content

Commit

Permalink
fix(Cascader): value is uncorrect on select the second value, close #957
Browse files Browse the repository at this point in the history
  • Loading branch information
Javey committed Jan 29, 2024
1 parent 39e994a commit d8e088d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions components/cascader/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,45 @@ describe('Cascader', () => {
expect(element.innerHTML).to.matchSnapshot();
expect(instance.get('value')).to.eql(['beijing', 'haidian']);
});

it('should select correct value', async () => {
class Demo extends Component {
static template = `
const {Cascader} = this;
<Cascader data={this.get('data')} v-model="value" />
`;
static defaults() {
return {
value: ['beijing', 'haidian'],
data: [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀区'
},
]
},
{
value: 'hunan',
label: '湖南',
},
]
}
}
private Cascader = Cascader;
}

const [instance, element] = mount(Demo);
dispatchEvent(element, 'click');
await wait();

const [dropdown1, dropdown2] = getElements('.k-cascader-menu');
const [item1, item2] = dropdown1.querySelectorAll(':scope > .k-dropdown-item');
dispatchEvent(item2, 'click');
await wait();
expect(instance.get('value')).to.eql(['hunan']);
});
});
2 changes: 1 addition & 1 deletion components/cascader/useValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function useValue() {
// maybe the showedValue has the leaf value when we set it on show menu,
// if we select by clicking, the showedValue has not the leaf value,
// no matter which case, we set the last value by level
const newValue = showedValue.value.slice(0);
const newValue = showedValue.value.slice(0, level);
newValue[level] = value;
setValue(newValue);
}
Expand Down

0 comments on commit d8e088d

Please sign in to comment.