Skip to content

Commit

Permalink
[FEATURE] Add allowDropdown option
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlouden committed Oct 11, 2019
1 parent 2ee1142 commit a7119d3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions addon/components/phone-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const PHONE_NUMBER_FORMAT = 'E164' // https://en.wikipedia.org/wiki/E.164
A phone-input component. Usage:
```hbs
{{phone-input
allowDropdown=false
autoPlaceholder='aggressive'
initialCountry='fr'
number='123'
Expand Down Expand Up @@ -44,6 +45,14 @@ export default Component.extend({
*/
this.number = this.number || null

/**
Whether or not to allow the dropdown. If disabled, there is no dropdown arrow, and the selected flag is not clickable. Also we display the selected flag on the right instead because it is just a marker of state.
@argument allowDropdown
@type {boolean}
*/
this.allowDropdown = this.allowDropdown || this.allowDropdown === undefined

/**
Add or remove input placeholder with an example number for the selected
country. Possible values are 'polite', 'aggressive' and 'off'. Defaults to
Expand Down Expand Up @@ -135,6 +144,7 @@ export default Component.extend({
this._super(...arguments)

const {
allowDropdown,
autoPlaceholder,
initialCountry,
onlyCountries,
Expand All @@ -146,6 +156,7 @@ export default Component.extend({
var _iti = intlTelInput(input, {
autoHideDialCode: true,
nationalMode: true,
allowDropdown,
autoPlaceholder,
initialCountry,
onlyCountries,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Component from '@ember/component'

export default Component.extend({
allowDropdown: null,
number: null,
separateDialNumber: null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,16 @@

{{demo.snippet "phone-input-separate-dial-option.hbs"}}
{{/docs-demo}}

<h2>`allowDropdown` option</h2>
{{#docs-demo as |demo|}}
{{#demo.example name="phone-input-allow-dropdown-option.hbs"}}

<p>{{phone-input allowDropdown=false initialCountry="fr" update=(action "handleUpdate")}}</p>

<p>The dropdown can be disabled.</p>

{{/demo.example}}

{{demo.snippet "phone-input-allow-dropdown-option.hbs"}}
{{/docs-demo}}
16 changes: 16 additions & 0 deletions tests/integration/components/phone-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,20 @@ module('Integration | Component | phone-input', function(hooks) {

this.set('country', 'pt')
})

test('can prevent the dropdown', async function(assert) {
assert.expect(1)

await this.owner.lookup('service:phone-input').load()

this.set('update', value => {
this.set('allowDropdown', value)
})

await render(
hbs`{{phone-input allowDropdown=false update=(action update)}}`
)

assert.dom('ul.country-list').doesNotExist()
})
})

0 comments on commit a7119d3

Please sign in to comment.