Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[Terra-Paginator] Added hidePageCount prop to hide default page count provided by Paginator #3924

Merged
merged 6 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions packages/terra-core-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## Unreleased

* Updated
* Updated test example to validate `hidePageCount` prop.
* Updated terra-list examples to demonstrate arrow key navigation within list and list sections.

## 1.42.0 - (September 26, 2023)

* Updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import ProgressivePaginator from 'terra-paginator/lib/ProgressivePaginator';
const ProgressivePaginatorWithCustomLabel = () => {
const [totalCount, setTotalCount] = useState();
const [currentPage, setCurrentPage] = useState(1);
const [hidePageCount, setHidePageCount] = useState(false);
const [pageLabel, setPageLabel] = useState('WebPage');

const changePages = (index) => {
setCurrentPage(index);
};
return (
<div>
<Button id="total-count-button" text="Set Total Count to 45" onClick={() => { setTotalCount(45); }} />
{/* eslint-disable-next-line no-console */}
<ProgressivePaginator pageLabel="WebPage" totalCount={totalCount} onPageChange={changePages} selectedPage={currentPage} />
<Button id="hide-count-button" text="Hide Page Count" onClick={() => { setHidePageCount(true); setPageLabel('WebPage 444 of 445'); }} />
<Button id="clear-page-lable-button" text="clear Page label" onClick={() => { setPageLabel(undefined); }} />
<ProgressivePaginator pageLabel={pageLabel} hidePageCount={hidePageCount} totalCount={totalCount} onPageChange={changePages} selectedPage={currentPage} />
</div>
);
};
Expand Down
3 changes: 3 additions & 0 deletions packages/terra-paginator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added
* Added `hidePageCount` prop to hide page count provided by paginator.

## 2.85.0 - (September 19, 2023)

* Added
Expand Down
22 changes: 12 additions & 10 deletions packages/terra-paginator/src/ControlledProgressivePaginator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const propTypes = {
* Allows user to set custom page label. _(usage note: User must pass translated text)_. It should not contain page number and total count details, which will lead to conflicts with built-in accessibility ARIA contexts.
*/
pageLabel: PropTypes.string,
/**
* ![IMPORTANT](https://badgen.net/badge/UX/Accessibility/blue)
* When specified allows user to set custom page count. User should provide custom page count as part `pageLabel` for best accessibility practices.
* _(usage note: when `pageLabel` is not provided page count will not be hidden and default page count is displayed for best accessibility practices)_.
*/
hidePageCount: PropTypes.bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a doc example for how and in what scenario this prop is used? I am having trouble understanding the purpose of this prop based on the test example.

Copy link
Contributor Author

@supreethmr supreethmr Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sycombs
Added examples for both custom page label and page count : 5fd4d93

};

class ControlledProgressivePaginator extends React.Component {
Expand Down Expand Up @@ -108,6 +114,7 @@ class ControlledProgressivePaginator extends React.Component {
ariaLabelledBy,
ariaLabel,
pageLabel,
hidePageCount,
} = this.props;
const totalPages = (totalCount) ? calculatePages(totalCount, itemCountPerPage) : 0;
const previousPageIndex = selectedPage === 1 ? 1 : selectedPage - 1;
Expand All @@ -116,14 +123,11 @@ class ControlledProgressivePaginator extends React.Component {
const renderFirstandLastButton = totalCount > 0;

const { messageId, messageAttributes } = getPageLabel(pageLabel, selectedPage, totalPages);
const pageDetails = (hidePageCount && pageLabel) ? <div>{pageLabel}</div> : <div>{intl.formatMessage({ id: messageId }, messageAttributes)}</div>;

const fullViewChildren = (
<>
<div>
{
intl.formatMessage({ id: messageId }, messageAttributes)
}
</div>
{pageDetails}
<ul className={cx('progressive-list')}>
{
renderFirstandLastButton && (
Expand Down Expand Up @@ -215,6 +219,7 @@ class ControlledProgressivePaginator extends React.Component {
ariaLabelledBy,
ariaLabel,
pageLabel,
hidePageCount,
} = this.props;
const totalPages = (totalCount) ? calculatePages(totalCount, itemCountPerPage) : 0;
const previousPageIndex = selectedPage === 1 ? 1 : selectedPage - 1;
Expand All @@ -223,14 +228,11 @@ class ControlledProgressivePaginator extends React.Component {
const renderFirstandLastButton = totalCount > 0;

const { messageId, messageAttributes } = getPageLabel(pageLabel, selectedPage, totalPages);
const pageDetails = (hidePageCount && pageLabel) ? <div>{pageLabel}</div> : <div>{intl.formatMessage({ id: messageId }, messageAttributes)}</div>;

const reducedViewChildren = (
<>
<div>
{
intl.formatMessage({ id: messageId }, messageAttributes)
}
</div>
{pageDetails}
<ul className={cx('progressive-list')}>
{
renderFirstandLastButton && (
Expand Down
22 changes: 12 additions & 10 deletions packages/terra-paginator/src/ProgressivePaginator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const propTypes = {
* Allows user to set custom page label. _(usage note: User must pass translated text)_. It should not contain page number and total count details, which will lead to conflicts with built-in accessibility ARIA contexts.
*/
pageLabel: PropTypes.string,
/**
* ![IMPORTANT](https://badgen.net/badge/UX/Accessibility/blue)
* When specified allows user to set custom page count. User should provide custom page count as part `pageLabel` for best accessibility practices.
* _(usage note: when `pageLabel` is not provided page count will not be hidden and default page count is displayed for best accessibility practices)_.
*/
hidePageCount: PropTypes.bool,
};

class ProgressivePaginator extends React.Component {
Expand Down Expand Up @@ -114,6 +120,7 @@ class ProgressivePaginator extends React.Component {
ariaLabelledBy,
ariaLabel,
pageLabel,
hidePageCount,
} = this.props;
const totalPages = (totalCount) ? calculatePages(totalCount, itemCountPerPage) : 0;
const { selectedPage } = this.state;
Expand All @@ -123,14 +130,11 @@ class ProgressivePaginator extends React.Component {
const renderFirstandLastButton = totalCount > 0;

const { messageId, messageAttributes } = getPageLabel(pageLabel, selectedPage, totalPages);
const pageDetails = (hidePageCount && pageLabel) ? <div>{pageLabel}</div> : <div>{intl.formatMessage({ id: messageId }, messageAttributes)}</div>;

const fullViewChildren = (
<>
<div>
{
intl.formatMessage({ id: messageId }, messageAttributes)
}
</div>
{pageDetails}
<ul className={cx('progressive-list')}>
{
renderFirstandLastButton && (
Expand Down Expand Up @@ -221,6 +225,7 @@ class ProgressivePaginator extends React.Component {
ariaLabelledBy,
ariaLabel,
pageLabel,
hidePageCount,
} = this.props;
const totalPages = (totalCount) ? calculatePages(totalCount, itemCountPerPage) : 0;
const { selectedPage } = this.state;
Expand All @@ -230,14 +235,11 @@ class ProgressivePaginator extends React.Component {
const renderFirstandLastButton = totalCount > 0;

const { messageId, messageAttributes } = getPageLabel(pageLabel, selectedPage, totalPages);
const pageDetails = (hidePageCount && pageLabel) ? <div>{pageLabel}</div> : <div>{intl.formatMessage({ id: messageId }, messageAttributes)}</div>;

const reducedViewChildren = (
<>
<div>
{
intl.formatMessage({ id: messageId }, messageAttributes)
}
</div>
{pageDetails}
<ul className={cx('progressive-list')}>
{
renderFirstandLastButton && (
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/terra-paginator/tests/wdio/paginator-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,15 @@ Terra.describeViewports('Controlled Paginator', ['large'], () => {
$('#total-count-button').click();
Terra.validates.element('custom page label with total count');
});

it('should display custom page count with custom page label when hidePageCount is set to true', () => {
$('#hide-count-button').click();
Terra.validates.element('custom page label with custom page count');
});

it('should display progressive paginator with default page count when page label is not provided', () => {
$('#clear-page-lable-button').click();
Terra.validates.element('paginator with default page count');
});
});
});