Skip to content

Commit

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

* chore: code clean

* fix: LGTM test

* chore: code clean

* fix: LGTM

* chore: code clean
  • Loading branch information
MadCcc authored Feb 8, 2022
1 parent eea408a commit 6153468
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
8 changes: 4 additions & 4 deletions examples/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const addressOptions = [
children: [],
},
{
label: '福建',
value: 'fj',
label: '福建 "',
value: 'fj "',
title: '测试标题',
children: [
{
label: '福州',
value: 'fuzhou',
label: '福州"',
value: 'fuzhou "',
children: [
{
label: '马尾',
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(/(?<!\\)"/g, '\\"')}"]`, // matches unescaped double quotes
);
ele?.scrollIntoView?.({ block: 'nearest' });
}
}, [activeValueCells]);
Expand Down
28 changes: 25 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,26 @@ describe('Cascader.Basic', () => {
wrapper.unmount();
});
});

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

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

1 comment on commit 6153468

@vercel
Copy link

@vercel vercel bot commented on 6153468 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.