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

feat(List): allow overriding role prop #3125

Merged
merged 1 commit into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/elements/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,22 @@ class List extends Component {

if (!childrenUtils.isNil(children)) {
return (
<ElementType {...rest} role='list' className={classes}>
<ElementType role='list' className={classes} {...rest}>
{children}
</ElementType>
)
}

if (!childrenUtils.isNil(content)) {
return (
<ElementType {...rest} role='list' className={classes}>
<ElementType role='list' className={classes} {...rest}>
{content}
</ElementType>
)
}

return (
<ElementType {...rest} role='list' className={classes}>
<ElementType role='list' className={classes} {...rest}>
{_.map(items, item => ListItem.create(item, { overrideProps: this.handleItemOverrides }))}
</ElementType>
)
Expand Down
8 changes: 4 additions & 4 deletions src/elements/List/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ class ListItem extends Component {
if (!childrenUtils.isNil(children)) {
return (
<ElementType
{...rest}
{...valueProp}
role='listitem'
className={classes}
onClick={this.handleClick}
{...rest}
>
{children}
</ElementType>
Expand All @@ -130,11 +130,11 @@ class ListItem extends Component {
if (!isValidElement(content) && _.isPlainObject(content)) {
return (
<ElementType
{...rest}
{...valueProp}
role='listitem'
className={classes}
onClick={this.handleClick}
{...rest}
>
{iconElement || imageElement}
{ListContent.create(content, {
Expand All @@ -150,11 +150,11 @@ class ListItem extends Component {
if (iconElement || imageElement) {
return (
<ElementType
{...rest}
{...valueProp}
role='listitem'
className={classes}
onClick={this.handleClick}
{...rest}
>
{iconElement || imageElement}
{(content || headerElement || descriptionElement) && (
Expand All @@ -170,11 +170,11 @@ class ListItem extends Component {

return (
<ElementType
{...rest}
{...valueProp}
role='listitem'
className={classes}
onClick={this.handleClick}
{...rest}
>
{headerElement}
{descriptionElement}
Expand Down
21 changes: 19 additions & 2 deletions test/specs/elements/List/List-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,32 @@ describe('List', () => {
describe('role', () => {
it('is accessibile with no items', () => {
const wrapper = shallow(<List />)

wrapper.should.have.prop('role', 'list')
})

it('is accessibile with items', () => {
const wrapper = shallow(<List items={items} />)

wrapper.should.have.prop('role', 'list')
})

it('allows overriding with no items', () => {
const wrapper = shallow(<List role='listbox' />)
wrapper.should.have.prop('role', 'listbox')
})

it('allows overriding with items', () => {
const wrapper = shallow(<List role='listbox' items={items} />)
wrapper.should.have.prop('role', 'listbox')
})

it('allows overriding with children', () => {
const wrapper = shallow(
<List role='listbox'>
<ListItem />
</List>,
)
wrapper.should.have.prop('role', 'listbox')
})
})

describe('shorthand', () => {
Expand Down
23 changes: 23 additions & 0 deletions test/specs/elements/List/ListItem-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,41 @@ describe('ListItem', () => {
it('adds role=listitem', () => {
shallow(<ListItem />).should.have.prop('role', 'listitem')
})

it('adds role=listitem with children', () => {
shallow(
<ListItem>
<div>Test</div>
</ListItem>,
).should.have.prop('role', 'listitem')
})

it('adds role=listitem with content', () => {
shallow(<ListItem content={<div />} />).should.have.prop('role', 'listitem')
})

it('adds role=listitem with icon', () => {
shallow(<ListItem icon='user' />).should.have.prop('role', 'listitem')
})

it('allows role override without children', () => {
shallow(<ListItem role='option' />).should.have.prop('role', 'option')
})

it('allows role override with children', () => {
shallow(
<ListItem role='option'>
<div>Test</div>
</ListItem>,
).should.have.prop('role', 'option')
})

it('allows role override with content', () => {
shallow(<ListItem role='option' content={<div />} />).should.have.prop('role', 'option')
})

it('allows role override with icon', () => {
shallow(<ListItem role='option' icon='user' />).should.have.prop('role', 'option')
})
})
})