Skip to content

Commit

Permalink
fix: should support quotes in label and value (#247)
Browse files Browse the repository at this point in the history
* fix: cascader should support double quotes in value and label (#245)

* fix: label should support "

* chore: code clean

* fix: LGTM test

* chore: code clean

* fix: LGTM

* chore: code clean

* fix: use common reg

* test: test case update

* test: test case update

* test: test case

* test: test case

* test: test case

* test: test case
  • Loading branch information
MadCcc authored Feb 8, 2022
1 parent 199eb53 commit 775c280
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
12 changes: 6 additions & 6 deletions examples/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
},
],
},
Expand Down
4 changes: 3 additions & 1 deletion src/OptionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ const RefOptionList = React.forwardRef<RefOptionListProps>((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]);
Expand Down
29 changes: 26 additions & 3 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -806,4 +806,27 @@ describe('Cascader.Basic', () => {
wrapper.unmount();
});
});

it('should support double quote in label and value', () => {
const wrapper = mount(
<Cascader
options={[
{
label: 'bamboo "',
value: 'bamboo "',
},
{
// prettier-ignore
label: 'bamboo \"',
// prettier-ignore
value: 'bamboo \"',
},
]}
open
/>,
);

wrapper.find(`li[data-path-key]`).at(0).simulate('click');
wrapper.find(`li[data-path-key]`).at(1).simulate('click');
});
});

1 comment on commit 775c280

@vercel
Copy link

@vercel vercel bot commented on 775c280 Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.