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

fix(pagination): add pageSizeInputDisabled prop to Pagination #6070

Merged
merged 12 commits into from
Jun 12, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -3899,9 +3899,7 @@ Map {
"page": Object {
"type": "number",
},
"pageInputDisabled": Object {
"type": "bool",
},
"pageInputDisabled": [Function],
"pageNumberText": Object {
"type": "string",
},
Expand Down
7 changes: 5 additions & 2 deletions packages/react/src/components/Pagination/Pagination-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import {
import Pagination from '../Pagination';

const props = () => ({
disabled: boolean('Disable backward/forward buttons (disabled)', false),
disabled: boolean('Disable page inputs (disabled)', false),
page: number('The current page (page)', 1),
totalItems: number('Total number of items (totalItems)', 103),
pagesUnknown: boolean('Total number of items unknown (pagesUnknown)', false),
pageInputDisabled: boolean('Disable page input (pageInputDisabled)', false),
pageInputDisabled: boolean(
'[Deprecated]: Disable page input (pageInputDisabled)',
false
),
backwardText: text(
'The description for the backward icon (backwardText)',
'Previous page'
Expand Down
24 changes: 16 additions & 8 deletions packages/react/src/components/Pagination/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Select from '../Select';
import SelectItem from '../SelectItem';
import { equals } from '../../tools/array';
import Button from '../Button';
import deprecate from '../../prop-types/deprecate';

const { prefix } = settings;

Expand Down Expand Up @@ -99,7 +100,7 @@ export default class Pagination extends Component {
totalItems: PropTypes.number,

/**
* `true` if the backward/forward buttons should be disabled.
* `true` if the backward/forward buttons, as well as the page select elements, should be disabled.
*/
disabled: PropTypes.bool,

Expand All @@ -125,9 +126,12 @@ export default class Pagination extends Component {
isLastPage: PropTypes.bool,

/**
* `true` if the select box to change the page should be disabled.
* Deprecated; `true` if the select box to change the page should be disabled.
*/
pageInputDisabled: PropTypes.bool,
pageInputDisabled: deprecate(
PropTypes.bool,
`\nThe prop \`pageInputDisabled\` for Pagination has been deprecated, as the feature of \`pageInputDisabled\` has been combined with the general \`disabled\` prop.`
tw15egan marked this conversation as resolved.
Show resolved Hide resolved
),
};

static defaultProps = {
Expand Down Expand Up @@ -189,7 +193,10 @@ export default class Pagination extends Component {
Math.max(Math.ceil(this.props.totalItems / this.state.pageSize), 1)
) {
this.setState({ page });
this.props.onChange({ page, pageSize: this.state.pageSize });
this.props.onChange({
page,
pageSize: this.state.pageSize,
});
}
};

Expand Down Expand Up @@ -233,6 +240,7 @@ export default class Pagination extends Component {
pageNumberText, // eslint-disable-line no-unused-vars
pagesUnknown,
isLastPage,
disabled,
pageInputDisabled,
totalItems,
onChange, // eslint-disable-line no-unused-vars
Expand All @@ -244,16 +252,15 @@ export default class Pagination extends Component {
const inputId = id || this.uniqueId;
const { page: statePage, pageSize: statePageSize } = this.state;
const totalPages = Math.max(Math.ceil(totalItems / statePageSize), 1);
const backButtonDisabled = this.props.disabled || statePage === 1;
const backButtonDisabled = disabled || statePage === 1;
const backButtonClasses = classnames(
`${prefix}--pagination__button`,
`${prefix}--pagination__button--backward`,
{
[`${prefix}--pagination__button--no-index`]: backButtonDisabled,
}
);
const forwardButtonDisabled =
this.props.disabled || statePage === totalPages;
const forwardButtonDisabled = disabled || statePage === totalPages;
const forwardButtonClasses = classnames(
`${prefix}--pagination__button`,
`${prefix}--pagination__button--forward`,
Expand All @@ -279,6 +286,7 @@ export default class Pagination extends Component {
noLabel
inline
onChange={this.handleSizeChange}
disabled={pageInputDisabled || disabled}
value={statePageSize}>
{pageSizes.map((size) => (
<SelectItem key={size} value={size} text={String(size)} />
Expand Down Expand Up @@ -306,7 +314,7 @@ export default class Pagination extends Component {
hideLabel
onChange={this.handlePageInputChange}
value={statePage}
disabled={pageInputDisabled}>
disabled={pageInputDisabled || disabled}>
{selectItems}
</Select>
<span className={`${prefix}--pagination__text`}>
Expand Down