mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 00:14:18 +00:00
fix(Highlight): render correctly when keywords is empty (#12829)
This commit is contained in:
@@ -100,6 +100,14 @@ export default defineComponent({
|
|||||||
|
|
||||||
const lastChunk = chunks[chunks.length - 1];
|
const lastChunk = chunks[chunks.length - 1];
|
||||||
|
|
||||||
|
if (!lastChunk) {
|
||||||
|
chunks.push({
|
||||||
|
start: 0,
|
||||||
|
end: sourceString.length,
|
||||||
|
highlight: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (lastChunk && lastChunk.end < sourceString.length) {
|
if (lastChunk && lastChunk.end < sourceString.length) {
|
||||||
chunks.push({
|
chunks.push({
|
||||||
start: lastChunk.end,
|
start: lastChunk.end,
|
||||||
|
@@ -95,3 +95,18 @@ test('empty text should not be matched', () => {
|
|||||||
|
|
||||||
expect(tags[0].text()).toEqual('bc');
|
expect(tags[0].text()).toEqual('bc');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('empty keywords should correctly rendered', () => {
|
||||||
|
const wrapper = mount(Highlight, {
|
||||||
|
props: {
|
||||||
|
keywords: '',
|
||||||
|
sourceString: 'abcd',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const highlight = wrapper.find('.van-highlight');
|
||||||
|
const tags = highlight.findAll('.van-highlight__tag');
|
||||||
|
|
||||||
|
expect(highlight.text()).toEqual('abcd');
|
||||||
|
expect(tags.length).toEqual(0);
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user