Skip to content

Commit

Permalink
Revert "fix: quote in key should not cause tabs crash (#655)"
Browse files Browse the repository at this point in the history
This reverts commit 18550e0.
  • Loading branch information
MadCcc committed Mar 9, 2023
1 parent 87eae44 commit 86ab6e3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/TabNavList/TabNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import classNames from 'classnames';
import KeyCode from 'rc-util/lib/KeyCode';
import * as React from 'react';
import type { EditableConfig, Tab } from '../interface';
import { genDataNodeKey } from '../util';

export interface TabNodeProps {
id: string;
Expand Down Expand Up @@ -57,7 +56,7 @@ function TabNode({
<div
key={key}
// ref={ref}
data-node-key={genDataNodeKey(key)}
data-node-key={key}
className={classNames(tabPrefix, {
[`${tabPrefix}-with-remove`]: removable,
[`${tabPrefix}-active`]: active,
Expand Down
4 changes: 2 additions & 2 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
TabsLocale,
} from '../interface';
import TabContext from '../TabContext';
import { genDataNodeKey, stringify } from '../util';
import { stringify } from '../util';
import AddButton from './AddButton';
import ExtraContent from './ExtraContent';
import OperationNode from './OperationNode';
Expand Down Expand Up @@ -311,7 +311,7 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
setTabSizes(() => {
const newSizes: TabSizeMap = new Map();
tabs.forEach(({ key }) => {
const btnNode = tabListRef.current?.querySelector<HTMLElement>(`[data-node-key="${genDataNodeKey(key)}"]`);
const btnNode = tabListRef.current?.querySelector<HTMLElement>(`[data-node-key="${key}"]`);
if (btnNode) {
newSizes.set(key, {
width: btnNode.offsetWidth,
Expand Down
5 changes: 0 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ export function stringify<K extends string | number | symbol, V>(obj: Record<K,

return JSON.stringify(tgt);
}

const RC_TABS_DOUBLE_QUOTE = 'TABS_DQ';
export function genDataNodeKey(key: string): string {
return key.replace(/"/g, RC_TABS_DOUBLE_QUOTE);
}
4 changes: 0 additions & 4 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,4 @@ describe('Tabs.Basic', () => {
const { container } = render(getTabs({ tabBarStyle: { background: 'red' } }));
expect(container.querySelector('.rc-tabs-nav')).toHaveStyle({ background: 'red' });
});

it('key contains double quote should not crash', () => {
render(<Tabs items={[{key: '"key"', label: 'test'}]} />)
})
});

1 comment on commit 86ab6e3

@vercel
Copy link

@vercel vercel bot commented on 86ab6e3 Mar 9, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

tabs – ./

tabs-react-component.vercel.app
tabs-git-master-react-component.vercel.app

Please sign in to comment.