Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "getPopupContainer" prop #491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/TabNavList/OperationNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface OperationNodeProps {
removeAriaLabel?: string;
onTabClick: (key: React.Key, e: React.MouseEvent | React.KeyboardEvent) => void;
tabMoving?: boolean;
getPopupContainer?: (node: HTMLElement) => HTMLElement;
popupClassName?: string;
}

Expand All @@ -43,6 +44,7 @@ function OperationNode(
rtl,
removeAriaLabel,
onTabClick,
getPopupContainer,
popupClassName,
}: OperationNodeProps,
ref: React.Ref<HTMLDivElement>,
Expand Down Expand Up @@ -196,6 +198,7 @@ function OperationNode(
overlayClassName={classNames(overlayClassName, popupClassName)}
mouseEnterDelay={0.1}
mouseLeaveDelay={0.1}
getPopupContainer={getPopupContainer}
>
<button
type="button"
Expand Down
1 change: 1 addition & 0 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface TabNavListProps {
onTabClick: (activeKey: string, e: React.MouseEvent | React.KeyboardEvent) => void;
onTabScroll?: OnTabScroll;
children?: (node: React.ReactElement) => React.ReactElement;
getPopupContainer?: (node: HTMLElement) => HTMLElement;
popupClassName?: string;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface TabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'o
onTabScroll?: OnTabScroll;

editable?: EditableConfig;
getPopupContainer?: (node: HTMLElement) => HTMLElement;

// Accessibility
locale?: TabsLocale;
Expand Down Expand Up @@ -112,6 +113,7 @@ function Tabs(
onChange,
onTabClick,
onTabScroll,
getPopupContainer,
popupClassName,
...restProps
}: TabsProps,
Expand Down Expand Up @@ -217,6 +219,7 @@ function Tabs(
extra: tabBarExtraContent,
style: tabBarStyle,
panes: children,
getPopupContainer,
popupClassName,
};

Expand Down
11 changes: 8 additions & 3 deletions tests/overflow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React from 'react';
import type { ReactWrapper } from 'enzyme';
import { mount } from 'enzyme';
import KeyCode from 'rc-util/lib/KeyCode';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import { act } from 'react-dom/test-utils';
import { TabPane } from '../src';
import {
getOffsetSizeFunc,
getTabs,
triggerResize,
getTransformX,
getTransformY,
triggerResize,
} from './common/util';
import { TabPane } from '../src';

describe('Tabs.Overflow', () => {
let domSpy: ReturnType<typeof spyElementPrototypes>;
Expand Down Expand Up @@ -375,6 +374,12 @@ describe('Tabs.Overflow', () => {
expect(wrapper.find('.rc-tabs-dropdown-menu').first().text()).not.toContain('miu');
});

it('should support getPopupContainer', () => {
const getPopupContainer = trigger => trigger.parentNode;
const wrapper = mount(getTabs({ getPopupContainer }));
expect(wrapper.find('Trigger').first().props().getPopupContainer).toBe(getPopupContainer);
});

it('should support popupClassName', () => {
jest.useFakeTimers();
const wrapper = mount(getTabs({ popupClassName: 'custom-popup' }));
Expand Down