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

fix(DropdownItem): add className to element shorthands #1256

Merged
merged 3 commits into from
Feb 22, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React from 'react'
import { Dropdown } from 'semantic-ui-react'

const DropdownExampleDescription = () => (
<Dropdown text='Filter' floating labeled button className='icon'>
{/* <i class="filter icon"></i> */}
<Dropdown text='Filter Tags' floating labeled button icon='filter' className='icon'>
<Dropdown.Menu>
<Dropdown.Header icon='tags' content='Filter by tag' />
<Dropdown.Divider />
<Dropdown.Item description='2 new' text='Important' />
<Dropdown.Item description='10 new' text='Announcement' />
<Dropdown.Item description='10 new' text='Hopper' />
<Dropdown.Item description='5 new' text='Discussion' />
</Dropdown.Menu>
</Dropdown>
Expand Down
25 changes: 10 additions & 15 deletions src/modules/Dropdown/DropdownItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,25 @@ export default class DropdownItem extends Component {
const labelElement = Label.create(label)
const descriptionElement = createShorthand(
'span',
val => ({ className: 'description', children: val }),
val => ({ children: val }),
description,
props => ({ className: 'description' })
)
const textElement = createShorthand(
'span',
val => ({ children: val }),
content || text,
props => ({ className: 'text' })
)

if (descriptionElement) {
return (
<ElementType {...rest} {...ariaOptions} className={classes} onClick={this.handleClick}>
{imageElement}
{iconElement}
{flagElement}
{labelElement}
{descriptionElement}
{createShorthand('span', val => ({ className: 'text', children: val }), content || text)}
</ElementType>
)
}

return (
<ElementType {...rest} {...ariaOptions} className={classes} onClick={this.handleClick}>
{imageElement}
{iconElement}
{flagElement}
{labelElement}
{content || text}
{descriptionElement}
{textElement}
</ElementType>
)
}
Expand Down
2 changes: 1 addition & 1 deletion test/specs/elements/Image/Image-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SUI } from 'src/lib'
import Dimmer from 'src/modules/Dimmer/Dimmer'
import * as common from 'test/specs/commonTests'

describe('Image Component', () => {
describe('Image', () => {
common.isConformant(Image)
common.hasSubComponents(Image, [ImageGroup])
common.hasUIClassName(Image)
Expand Down
24 changes: 12 additions & 12 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const dropdownMenuIsOpen = () => {

const nativeEvent = { nativeEvent: { stopImmediatePropagation: _.noop } }

describe('Dropdown Component', () => {
describe('Dropdown', () => {
beforeEach(() => {
attachTo = undefined
wrapper = undefined
Expand Down Expand Up @@ -769,12 +769,12 @@ describe('Dropdown Component', () => {
const nextItem = _.sample(_.without(options, initialItem))

wrapperMount(<Dropdown options={options} selection value={initialItem.value} />)
.find('.text')
.find('div.text')
.should.contain.text(initialItem.text)

wrapper
.setProps({ value: nextItem.value })
.find('.text')
.find('div.text')
.should.contain.text(nextItem.text)
})
})
Expand All @@ -784,7 +784,7 @@ describe('Dropdown Component', () => {
const text = faker.hacker.phrase()

wrapperRender(<Dropdown options={options} selection text={text} />)
.find('.text')
.find('div.text')
.should.contain.text(text)
})
it('prevents updates on item click if defined', () => {
Expand All @@ -797,7 +797,7 @@ describe('Dropdown Component', () => {
.simulate('click')

wrapper
.find('.text')
.find('div.text')
.should.contain.text(text)
})
it('is updated on item click if not already defined', () => {
Expand All @@ -814,7 +814,7 @@ describe('Dropdown Component', () => {

// text updated
wrapper
.find('.text')
.find('div.text')
.should.contain.text(item.text())
})
it('displays if value is 0', () => {
Expand All @@ -832,10 +832,10 @@ describe('Dropdown Component', () => {

// text updated
wrapper
.find('.text')
.find('div.text')
.should.contain.text(item.text())
})
it('does not display if value is \'\'', () => {
it("does not display if value is ''", () => {
const text = faker.hacker.noun()

wrapperMount(<Dropdown options={[{ value: '', text }]} selection />)
Expand All @@ -844,7 +844,7 @@ describe('Dropdown Component', () => {
.simulate('click')

wrapper
.find('.text')
.find('div.text')
.should.contain.text('')
})
it('does not display if value is null', () => {
Expand All @@ -856,7 +856,7 @@ describe('Dropdown Component', () => {
.simulate('click')

wrapper
.find('.text')
.find('div.text')
.should.contain.text('')
})
it('does not display if value is undefined', () => {
Expand All @@ -868,7 +868,7 @@ describe('Dropdown Component', () => {
.simulate('click')

wrapper
.find('.text')
.find('div.text')
.should.contain.text('')
})
})
Expand All @@ -887,7 +887,7 @@ describe('Dropdown Component', () => {
const trigger = <div className='trigger'>{text}</div>

wrapperRender(<Dropdown options={options} trigger={trigger} text={text} />)
.should.not.have.descendants('.text')
.should.not.have.descendants('div.text')
})
})

Expand Down
35 changes: 19 additions & 16 deletions test/specs/modules/Dropdown/DropdownItem-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ describe('DropdownItem', () => {
common.implementsShorthandProp(DropdownItem, {
propKey: 'flag',
ShorthandComponent: Flag,
mapValueToProps: val => ({ name: val }),
mapValueToProps: name => ({ name }),
})

common.implementsShorthandProp(DropdownItem, {
propKey: 'description',
ShorthandComponent: 'span',
mapValueToProps: val => ({
className: 'description',
children: val,
}),
mapValueToProps: children => ({ children }),
shorthandDefaultProps: props => ({ className: 'description' }),
})

common.implementsShorthandProp(DropdownItem, {
propKey: 'text',
ShorthandComponent: 'span',
mapValueToProps: children => ({ children }),
shorthandDefaultProps: props => ({ className: 'text' }),
})

describe('aria', () => {
Expand Down Expand Up @@ -71,19 +76,17 @@ describe('DropdownItem', () => {
})
})

describe('text', () => {
it('renders with wrapping span when description', () => {
const wrapper = shallow(<DropdownItem text='hey' description='description' />)

wrapper.should.have.descendants('span.text')
wrapper.text().should.include('hey')
describe('description', () => {
it('adds className="description" to element shorthand', () => {
shallow(<DropdownItem description={<strong />} />)
.should.have.descendants('strong.description')
})
})

it('renders without wrapping span when no description', () => {
const wrapper = shallow(<DropdownItem text='hey' />)

wrapper.should.not.have.descendants('span.text')
wrapper.text().should.equal('hey')
describe('text', () => {
it('adds className="text" to element shorthand', () => {
shallow(<DropdownItem text={<strong />} />)
.should.have.descendants('strong.text')
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/specs/modules/Search/Search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const openSearchResults = () => {

const nativeEvent = { nativeEvent: { stopImmediatePropagation: _.noop } }

describe('Search Component', () => {
describe('Search', () => {
beforeEach(() => {
attachTo = undefined
wrapper = undefined
Expand Down