Skip to content
Merged
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
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
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
10 changes: 8 additions & 2 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 && rc-np",
"start": "dumi dev",
"test": "rc-test"
"test": "rc-test",
"prepare": "husky && dumi setup"
},
"dependencies": {
"@rc-component/resize-observer": "^1.0.0",
Expand All @@ -58,7 +59,6 @@
"@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",
Expand All @@ -68,9 +68,12 @@
"father": "^4.0.0",
"gh-pages": "^6.1.0",
"history": "^5.3.0",
"husky": "^9.1.7",
"immutability-helper": "^3.0.1",
"less": "^4.1.3",
"lint-staged": "^15.5.0",
"preact-compat": "^3.16.0",
"prettier": "^3.5.3",
"rc-test": "^7.0.14",
"react": "^18.0.0",
"react-dnd": "^10.0.0",
Expand All @@ -84,6 +87,9 @@
"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 @@ -375,8 +375,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
Loading