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
25 changes: 25 additions & 0 deletions packages/material-ui-lab/src/Pagination/Pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createMount, getClasses } from '@material-ui/core/test-utils';
import describeConformance from '@material-ui/core/test-utils/describeConformance';
import { createClientRender } from 'test/utils/createClientRender';
import Pagination from './Pagination';
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';

describe('<Pagination />', () => {
let classes;
Expand Down Expand Up @@ -51,4 +52,28 @@ describe('<Pagination />', () => {

expect(handleChange.callCount).to.equal(1);
});

it('renders controls with correct order in rtl theme', () => {
const { getAllByRole } = render(
<ThemeProvider
theme={createMuiTheme({
direction: 'rtl',
})}
>
<Pagination count={5} page={3} showFirstButton showLastButton />
</ThemeProvider>,
);

const buttons = getAllByRole('button');

expect(buttons[0].querySelector('svg')).to.have.attribute('data-mui-test', 'LastPageIcon');
expect(buttons[1].querySelector('svg')).to.have.attribute('data-mui-test', 'NavigateNextIcon');
expect(buttons[2].textContent).to.equal('1');
expect(buttons[6].textContent).to.equal('5');
expect(buttons[7].querySelector('svg')).to.have.attribute(
'data-mui-test',
'NavigateBeforeIcon',
);
expect(buttons[8].querySelector('svg')).to.have.attribute('data-mui-test', 'FirstPageIcon');
});
});
25 changes: 20 additions & 5 deletions packages/material-ui-lab/src/PaginationItem/PaginationItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { fade, withStyles } from '@material-ui/core/styles';
import { fade, useTheme, withStyles } from '@material-ui/core/styles';
import ButtonBase from '@material-ui/core/ButtonBase';
import FirstPageIcon from '../internal/svg-icons/FirstPage';
import LastPageIcon from '../internal/svg-icons/LastPage';
Expand Down Expand Up @@ -208,6 +208,24 @@ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
...other
} = props;

const theme = useTheme();

const normalizedIcons =
theme.direction === 'rtl'
? {
previous: NavigateNextIcon,
next: NavigateBeforeIcon,
last: FirstPageIcon,
first: LastPageIcon,
}
: {
previous: NavigateBeforeIcon,
next: NavigateNextIcon,
first: FirstPageIcon,
last: LastPageIcon,
};
const Icon = normalizedIcons[type];

return type === 'start-ellipsis' || type === 'end-ellipsis' ? (
<div
ref={ref}
Expand Down Expand Up @@ -240,10 +258,7 @@ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
{...other}
>
{type === 'page' && page}
{type === 'previous' && <NavigateBeforeIcon className={classes.icon} />}
{type === 'next' && <NavigateNextIcon className={classes.icon} />}
{type === 'first' && <FirstPageIcon className={classes.icon} />}
{type === 'last' && <LastPageIcon className={classes.icon} />}
{Icon ? <Icon className={classes.icon} /> : null}
</ButtonBase>
);
});
Expand Down