Skip to content

Commit

Permalink
feat(PF4: Pagination): When empty array sent to pagination no per pag…
Browse files Browse the repository at this point in the history
…e should be visible (#2175)
  • Loading branch information
karelhala authored and tlabaj committed Jun 7, 2019
1 parent 0bebc18 commit cb97dfd
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const OptionsToggle = ({
widgetId,
onToggle,
isOpen,
showToggle,
toggleTemplate: ToggleTemplate
}) => (
<div className={css(styles.optionsMenuToggle, getModifier(styles, 'plain'), getModifier(styles, 'text'))}>
Expand All @@ -24,18 +25,20 @@ const OptionsToggle = ({
<ToggleTemplate firstIndex={firstIndex} lastIndex={lastIndex} itemCount={itemCount} itemsTitle={itemsTitle} />
)}
</span>
<button
className={css(styles.optionsMenuToggleButton)}
id={`${widgetId}-toggle`}
aria-haspopup="listbox"
aria-labelledby={`${widgetId}-toggle ${widgetId}-label`}
aria-label={optionsToggle}
aria-expanded={isOpen}
onClick={() => onToggle(!isOpen)}
type="button"
>
<CaretDownIcon />
</button>
{showToggle && (
<button
className={css(styles.optionsMenuToggleButton)}
id={`${widgetId}-toggle`}
aria-haspopup="listbox"
aria-labelledby={`${widgetId}-toggle ${widgetId}-label`}
aria-label={optionsToggle}
aria-expanded={isOpen}
onClick={() => onToggle(!isOpen)}
type="button"
>
<CaretDownIcon />
</button>
)}
</div>
);

Expand All @@ -48,6 +51,7 @@ OptionsToggle.propTypes = {
widgetId: PropTypes.string,
onToggle: PropTypes.func,
isOpen: PropTypes.bool,
showToggle: PropTypes.bool,
toggleTemplate: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
};

Expand All @@ -60,6 +64,7 @@ OptionsToggle.defaultProps = {
widgetId: '',
onToggle: () => undefined,
isOpen: false,
showToggle: true,
toggleTemplate: ''
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('component render', () => {
expect(wrapper).toMatchSnapshot();
});

test('empty per page options', () => {
const wrapper = mount(<Pagination itemCount={40} perPageOptions={[]} />);
expect(wrapper).toMatchSnapshot();
});

test('no items', () => {
const wrapper = mount(<Pagination itemCount={0} />);
expect(wrapper).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class PaginationOptionsMenu extends Component {
toggle={
<OptionsToggle
optionsToggle={optionsToggle}
showToggle={perPageOptions && perPageOptions.length > 0}
itemsTitle={itemsTitle}
onToggle={this.onToggle}
isOpen={this.state.isOpen}
Expand Down
Loading

0 comments on commit cb97dfd

Please sign in to comment.