Skip to content

Commit

Permalink
fix: custom class prop update should not be cumulative (#349)
Browse files Browse the repository at this point in the history
* fix: make custom classes update instead of stack up

* test: coverage for custom classes
  • Loading branch information
mcataford authored Jun 16, 2020
1 parent d769a1e commit edbe061
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/IntlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1257,14 +1257,16 @@ class IntlTelInput extends Component {
}

render() {
this.wrapperClass[this.props.containerClassName] = true
const inputClass = this.props.inputClassName
const wrapperStyle = Object.assign({}, this.props.style || {})

this.wrapperClass['allow-dropdown'] = this.allowDropdown
this.wrapperClass.expanded = this.state.showDropdown

const wrapperClass = classNames(this.wrapperClass)
const wrapperClass = classNames(
this.wrapperClass,
this.props.containerClassName
)

const titleTip = this.selectedCountryData
? `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}`
Expand Down
20 changes: 20 additions & 0 deletions src/components/__tests__/IntlTelInput.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { shallow } from 'enzyme'

import IntlTelInput from '../IntlTelInput'

describe('Style customization', () => {
it('correctly applies user-supplied classes on outer container', () => {
const component = shallow(<IntlTelInput />)
const mockClass = 'mock-class-1'
component.setProps({ containerClassName: mockClass })
expect(component.props().className).toMatchInlineSnapshot(
`"allow-dropdown mock-class-1"`
)
const otherMockClass = 'mock-class-2'
component.setProps({ containerClassName: otherMockClass })
expect(component.props().className).toMatchInlineSnapshot(
`"allow-dropdown mock-class-2"`
)
})
})

0 comments on commit edbe061

Please sign in to comment.