Skip to content
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
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Fixed `ToastManager` from not working correctly in `React.StrictMode` ([#1741](https://github.com/Shopify/polaris-react/pull/1741))
- Updated translation.yml with the new locales path ([#1649](https://github.com/Shopify/polaris-react/pull/1649))
- Fixed accessibility issue with `Tabs` list item presentation role ([#1958](https://github.com/Shopify/polaris-react/pull/1958))
- Removed `Tooltip` on disabled `Pagination` buttons ([#1963](https://github.com/Shopify/polaris-react/pull/1963))

### Documentation

Expand Down
24 changes: 13 additions & 11 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,19 @@ export default function Pagination({
</button>
);

const constructedPrevious = previousTooltip ? (
<Tooltip content={previousTooltip}>{previousButton}</Tooltip>
) : (
previousButton
);

const constructedNext = nextTooltip ? (
<Tooltip content={nextTooltip}>{nextButton}</Tooltip>
) : (
nextButton
);
const constructedPrevious =
previousTooltip && hasPrevious ? (
<Tooltip content={previousTooltip}>{previousButton}</Tooltip>
) : (
previousButton
);

const constructedNext =
nextTooltip && hasNext ? (
<Tooltip content={nextTooltip}>{nextButton}</Tooltip>
) : (
nextButton
);

const previousButtonEvents =
previousKeys &&
Expand Down
50 changes: 35 additions & 15 deletions src/components/Pagination/tests/Pagination.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,46 @@ describe('<Pagination />', () => {
removeEventListener.mockRestore();
});

it('renders a tooltip if nextTooltip is provided', () => {
const pagination = mountWithAppProvider(<Pagination nextTooltip="k" />);
pagination.find(Tooltip).simulate('focus');
describe('tooltip', () => {
it('renders a tooltip if nextTooltip is provided and hasNext is true', () => {
const pagination = mountWithAppProvider(
<Pagination nextTooltip="k" hasNext />,
);
pagination.find(Tooltip).simulate('focus');

expect(findByTestID(pagination, 'TooltipOverlayLabel').text()).toBe('k');
});
expect(findByTestID(pagination, 'TooltipOverlayLabel').text()).toBe('k');
});

it('renders a tooltip if previousToolTip is provided', () => {
const pagination = mountWithAppProvider(<Pagination previousTooltip="j" />);
pagination.find(Tooltip).simulate('focus');
it('does not render a tooltip if nextTooltip is provided and hasNext is false', () => {
const pagination = mountWithAppProvider(
<Pagination nextTooltip="k" hasNext={false} />,
);
expect(pagination.find(Tooltip)).toHaveLength(0);
});

expect(findByTestID(pagination, 'TooltipOverlayLabel').text()).toBe('j');
});
it('renders a tooltip if previousToolTip is provided and hasPrevious is true', () => {
const pagination = mountWithAppProvider(
<Pagination previousTooltip="j" hasPrevious />,
);
pagination.find(Tooltip).simulate('focus');

it('renders a tooltip for nextToolTip and previousToolTip when they are provided', () => {
const pagination = mountWithAppProvider(
<Pagination previousTooltip="j" nextTooltip="k" />,
);
expect(findByTestID(pagination, 'TooltipOverlayLabel').text()).toBe('j');
});

it('does not render tooltip if previousToolTip is provided and hasPrevious is false', () => {
const pagination = mountWithAppProvider(
<Pagination previousTooltip="j" hasPrevious={false} />,
);
expect(pagination.find(Tooltip)).toHaveLength(0);
});

expect(pagination.find(Tooltip)).toHaveLength(2);
it('renders a tooltip for nextToolTip and previousToolTip when they are provided and hasPrevious and hasNext are true', () => {
const pagination = mountWithAppProvider(
<Pagination previousTooltip="j" nextTooltip="k" hasPrevious hasNext />,
);

expect(pagination.find(Tooltip)).toHaveLength(2);
});
});

it('adds a keypress event for nextKeys', () => {
Expand Down