Skip to content

Commit

Permalink
[EuiBasicTable] Hide paginationBar in when there is no data (#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreadelrio authored Dec 9, 2019
1 parent 53880eb commit 6a193bc
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fixed UX/focus bug in `EuiDataGrid` when using keyboard shortcuts to paginate ([#2602](https://github.com/elastic/eui/pull/2602))
- Fixed `EuiIcon` accessibility by adding a `title` prop and a default `aria-label` ([#2554](https://github.com/elastic/eui/pull/2554))
- Fixed `EuiDataGrid`'s in-memory sorting of numeric columns when the cell data contains multiple digit groups ([#2603](https://github.com/elastic/eui/pull/2603))
- Improved pagination in `EuiBasicTable`. `paginationBar` is hidden when there is no data and `EuiPagination` is displayed even when there is only one page ([#2598](https://github.com/elastic/eui/pull/#2598))

## [`17.0.0`](https://github.com/elastic/eui/tree/v17.0.0)

Expand Down
6 changes: 3 additions & 3 deletions src/components/basic_table/basic_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export class EuiBasicTable<T = any> extends Component<
);

const table = this.renderTable();
const paginationBar = this.renderPaginationBar();
const paginationBar = this.renderPaginationBar(items.length);

return (
<div className={classes} {...rest}>
Expand Down Expand Up @@ -1092,9 +1092,9 @@ export class EuiBasicTable<T = any> extends Component<
return profile.align;
}

renderPaginationBar() {
renderPaginationBar(itemsLength: number) {
const { error, pagination, onChange } = this.props;
if (!error && pagination) {
if (!error && pagination && itemsLength > 0) {
if (!onChange) {
throw new Error(`The Basic Table is configured with pagination but [onChange] is
not configured. This callback must be implemented to handle pagination changes`);
Expand Down
62 changes: 61 additions & 1 deletion src/components/pagination/__snapshots__/pagination.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiPagination is rendered 1`] = `<span />`;
exports[`EuiPagination is rendered 1`] = `
<div
aria-label="aria-label"
class="euiPagination testClass1 testClass2"
data-test-subj="test subject string"
role="group"
>
<button
aria-label="Previous page"
class="euiButtonIcon euiButtonIcon--text"
data-test-subj="pagination-button-previous"
type="button"
>
<svg
aria-hidden="true"
aria-label=""
class="euiIcon euiIcon--medium euiIcon-isLoading euiButtonIcon__icon"
focusable="false"
height="16"
role="img"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
/>
</button>
<button
aria-label="Page 1 of 1"
class="euiButtonEmpty euiButtonEmpty--text euiButtonEmpty--xSmall euiPaginationButton euiPaginationButton--hideOnMobile"
data-test-subj="pagination-button-0"
type="button"
>
<span
class="euiButtonEmpty__content"
>
<span
class="euiButtonEmpty__text"
>
1
</span>
</span>
</button>
<button
aria-label="Next page"
class="euiButtonIcon euiButtonIcon--text"
data-test-subj="pagination-button-next"
type="button"
>
<svg
aria-hidden="true"
aria-label=""
class="euiIcon euiIcon--medium euiIcon-isLoading euiButtonIcon__icon"
focusable="false"
height="16"
role="img"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
/>
</button>
</div>
`;
29 changes: 12 additions & 17 deletions src/components/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,23 @@ export const EuiPagination: FunctionComponent<Props> = ({
</EuiI18n>
);

if (pages.length > 1) {
const selectablePages = pages;
if (compressed) {
return (
<div className={classes} {...rest}>
{previousButton}
{nextButton}
</div>
);
}

const selectablePages = pages;
if (compressed) {
return (
<div className={classes} role="group" {...rest}>
<div className={classes} {...rest}>
{previousButton}
{firstPageButtons}
{selectablePages}
{lastPageButtons}
{nextButton}
</div>
);
}

// Don't render pagination if it isn't needed. Then span is here for a docs bug.
return <span />;
return (
<div className={classes} role="group" {...rest}>
{previousButton}
{firstPageButtons}
{selectablePages}
{lastPageButtons}
{nextButton}
</div>
);
};

0 comments on commit 6a193bc

Please sign in to comment.