-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Tooltip] Allow overriding internal components and their props #28692
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1092,6 +1092,96 @@ describe('<Tooltip />', () => { | |
}); | ||
}); | ||
|
||
describe('prop: components', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to test it? For instance, we didn't really test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
it('can render a different Popper component', () => { | ||
const CustomPopper = () => <div data-testid="CustomPopper" />; | ||
const { getByTestId } = render( | ||
<Tooltip title="Hello World" open components={{ Popper: CustomPopper }}> | ||
<button id="testChild" type="submit"> | ||
Hello World | ||
</button> | ||
</Tooltip>, | ||
); | ||
expect(getByTestId('CustomPopper')).toBeVisible(); | ||
}); | ||
|
||
it('can render a different Tooltip component', () => { | ||
const CustomTooltip = React.forwardRef((props, ref) => ( | ||
<div data-testid="CustomTooltip" ref={ref} /> | ||
)); | ||
const { getByTestId } = render( | ||
<Tooltip title="Hello World" open components={{ Tooltip: CustomTooltip }}> | ||
<button id="testChild" type="submit"> | ||
Hello World | ||
</button> | ||
</Tooltip>, | ||
); | ||
expect(getByTestId('CustomTooltip')).toBeVisible(); | ||
}); | ||
|
||
it('can render a different Arrow component', () => { | ||
const CustomArrow = React.forwardRef((props, ref) => ( | ||
<div data-testid="CustomArrow" ref={ref} /> | ||
)); | ||
const { getByTestId } = render( | ||
<Tooltip title="Hello World" open arrow components={{ Arrow: CustomArrow }}> | ||
<button id="testChild" type="submit"> | ||
Hello World | ||
</button> | ||
</Tooltip>, | ||
); | ||
expect(getByTestId('CustomArrow')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe('prop: componentsProps', () => { | ||
it('can provide custom props for the inner Popper component', () => { | ||
const { getByTestId } = render( | ||
<Tooltip | ||
title="Hello World" | ||
open | ||
componentsProps={{ popper: { 'data-testid': 'CustomPopper' } }} | ||
> | ||
<button id="testChild" type="submit"> | ||
Hello World | ||
</button> | ||
</Tooltip>, | ||
); | ||
expect(getByTestId('CustomPopper')).toBeVisible(); | ||
}); | ||
|
||
it('can provide custom props for the inner Tooltip component', () => { | ||
const { getByTestId } = render( | ||
<Tooltip | ||
title="Hello World" | ||
open | ||
componentsProps={{ tooltip: { 'data-testid': 'CustomTooltip' } }} | ||
> | ||
<button id="testChild" type="submit"> | ||
Hello World | ||
</button> | ||
</Tooltip>, | ||
); | ||
expect(getByTestId('CustomTooltip')).toBeVisible(); | ||
}); | ||
|
||
it('can provide custom props for the inner Arrow component', () => { | ||
const { getByTestId } = render( | ||
<Tooltip | ||
title="Hello World" | ||
open | ||
arrow | ||
componentsProps={{ arrow: { 'data-testid': 'CustomArrow' } }} | ||
> | ||
<button id="testChild" type="submit"> | ||
Hello World | ||
</button> | ||
</Tooltip>, | ||
); | ||
expect(getByTestId('CustomArrow')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe('user-select state', () => { | ||
let prevWebkitUserSelect; | ||
beforeEach(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend this todo convention,
It reduces the chance to forget something. There are already instances for v5 and v6 in the codebase.