Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ export default () => {
}

const onTabClick = (key: string) => {
console.log('key', key);
console.log('onTabClick', key);
};

const onChange = (key: string) => {
console.log('onChange', key);
};

return (
<React.StrictMode>
<Tabs
tabBarExtraContent="extra"
onTabClick={onTabClick}
onChange={onChange}
direction={direction}
items={items}
/>
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"now-build": "npm run build",
"prepublishOnly": "npm run lint && npm run test && npm run compile && np --yolo --no-publish",
"start": "dumi dev",
"test": "rc-test"
"test": "rc-test",
"prepare": "husky && dumi setup"
},
"dependencies": {
"@babel/runtime": "^7.11.2",
Expand All @@ -54,21 +55,17 @@
"@types/classnames": "^2.2.10",
"@types/enzyme": "^3.10.5",
"@types/jest": "^29.4.0",
"@types/keyv": "4.2.0",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.0.11",
"@umijs/fabric": "^4.0.1",
"coveralls": "^3.0.6",
"cross-env": "^7.0.2",
"dumi": "^2.0.0",
"eslint": "^8.54.0",
"eslint-plugin-jest": "^28.9.0",
"eslint-plugin-unicorn": "^56.0.1",
"fastclick": "~1.0.6",
"father": "^4.0.0",
"gh-pages": "^6.1.0",
"history": "^5.3.0",
"immutability-helper": "^3.0.1",
"husky": "^9.1.7",
"less": "^4.1.3",
"np": "^10.0.2",
"preact-compat": "^3.16.0",
Expand All @@ -78,13 +75,15 @@
"react-dnd-html5-backend": "^10.0.0",
"react-dom": "^18.0.0",
"react-sticky": "^6.0.3",
"sortablejs": "^1.7.0",
"typescript": "^5.3.2"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
},
"lint-staged": {
"*": "prettier --write --ignore-unknown"
},
"engines": {
"node": ">=8.x"
}
Expand Down
3 changes: 2 additions & 1 deletion src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ const TabNavList = React.forwardRef<HTMLDivElement, TabNavListProps>((props, ref
// Enter & Space
case 'Enter':
case 'Space': {
console.log('press', code);
e.preventDefault();
onTabClick(focusKey, e);
onTabClick(activeKey, e);
break;
}
// Backspace
Expand Down
5 changes: 4 additions & 1 deletion tests/accessibility.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,26 @@ describe('Tabs.Accessibility', () => {

it('should activate tab on Enter/Space', async () => {
const onTabClick = jest.fn();
const onChange = jest.fn();
const user = userEvent.setup();

render(createTabs({ onTabClick }));
render(createTabs({ onTabClick, onChange }));

// jump to first tab
await user.tab();

// activate tab
await user.keyboard(' ');
expect(onTabClick).toHaveBeenCalledTimes(1);
expect(onChange).not.toHaveBeenCalled();

// move focus to second tab
await user.keyboard('{ArrowRight}');

// activate tab
await user.keyboard('{Enter}');
expect(onTabClick).toHaveBeenCalledTimes(2);
expect(onChange).not.toHaveBeenCalled();
});

it('should not navigate to disabled tabs', async () => {
Expand Down