diff --git a/examples/debug.tsx b/examples/debug.tsx index 74261d58..37ce9445 100644 --- a/examples/debug.tsx +++ b/examples/debug.tsx @@ -10,17 +10,17 @@ const addressOptions = [ children: [], }, { - label: '福建', - value: 'fj', + label: '福建 \\"', + value: 'fj \\"', title: '测试标题', children: [ { - label: '福州', - value: 'fuzhou', + label: '福州"', + value: 'fuzhou"', children: [ { - label: '马尾', - value: 'mawei', + label: '马尾"', + value: 'mawei"', }, ], }, diff --git a/src/OptionList/index.tsx b/src/OptionList/index.tsx index 21def516..6b16451d 100644 --- a/src/OptionList/index.tsx +++ b/src/OptionList/index.tsx @@ -148,7 +148,9 @@ const RefOptionList = React.forwardRef((props, ref) => { for (let i = 0; i < activeValueCells.length; i += 1) { const cellPath = activeValueCells.slice(0, i + 1); const cellKeyPath = toPathKey(cellPath); - const ele = containerRef.current?.querySelector(`li[data-path-key="${cellKeyPath}"]`); + const ele = containerRef.current?.querySelector( + `li[data-path-key="${cellKeyPath.replace(/\\{0,2}"/g, '\\"')}"]`, // matches unescaped double quotes + ); ele?.scrollIntoView?.({ block: 'nearest' }); } }, [activeValueCells]); diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 871e2cfb..b3c08f5f 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -1,11 +1,11 @@ /* eslint-disable react/jsx-no-bind */ -import React from 'react'; -import { resetWarned } from 'rc-util/lib/warning'; import { spyElementPrototypes } from 'rc-util/lib/test/domHook'; -import { mount } from './enzyme'; +import { resetWarned } from 'rc-util/lib/warning'; +import React from 'react'; import Cascader from '../src'; import { addressOptions, optionsForActiveMenuItems } from './demoOptions'; +import { mount } from './enzyme'; describe('Cascader.Basic', () => { let selectedValue; @@ -806,4 +806,27 @@ describe('Cascader.Basic', () => { wrapper.unmount(); }); }); + + it('should support double quote in label and value', () => { + const wrapper = mount( + , + ); + + wrapper.find(`li[data-path-key]`).at(0).simulate('click'); + wrapper.find(`li[data-path-key]`).at(1).simulate('click'); + }); });