Skip to content

Commit 72d82a3

Browse files
fix(PaginationLink): handle empty children array (#511)
Preact defaults to empty array for children, this will check for that and null it out. Closes #494
1 parent e1bdadb commit 72d82a3

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/PaginationLink.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ const PaginationLink = (props) => {
4848
}
4949

5050
let children = props.children;
51+
if (children && !children.length) {
52+
children = null;
53+
}
54+
5155
if (previous || next) {
5256
children = [
5357
<span

src/__tests__/PaginationLink.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ describe('PaginationLink', () => {
3737
expect(wrapper.find('.sr-only').text()).toBe('Next');
3838
});
3939

40+
it('should render default previous caret with children as an empty array', () => {
41+
const wrapper = shallow(<PaginationLink previous children={[]} />);
42+
43+
expect(wrapper.prop('aria-label')).toBe('Previous');
44+
expect(wrapper.find({ 'aria-hidden': 'true' }).text()).toBe('\u00ab');
45+
expect(wrapper.find('.sr-only').text()).toBe('Previous');
46+
});
47+
48+
it('should render default next caret with children as an empty array', () => {
49+
const wrapper = shallow(<PaginationLink next children={[]} />);
50+
51+
expect(wrapper.prop('aria-label')).toBe('Next');
52+
expect(wrapper.find({ 'aria-hidden': 'true' }).text()).toBe('\u00bb');
53+
expect(wrapper.find('.sr-only').text()).toBe('Next');
54+
});
55+
4056
it('should render custom aria label', () => {
4157
const wrapper = shallow(<PaginationLink next aria-label="Yo" />);
4258

0 commit comments

Comments
 (0)