This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "replace gh-select-native with one-way-select"
This reverts commit e9d75da.
- Loading branch information
Showing
7 changed files
with
84 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Component from 'ember-component'; | ||
import {reads} from 'ember-computed'; | ||
|
||
function K() { | ||
return this; | ||
} | ||
|
||
export default Component.extend({ | ||
content: null, | ||
prompt: null, | ||
optionValuePath: 'id', | ||
optionLabelPath: 'title', | ||
selection: null, | ||
action: K, // action to fire on change | ||
|
||
// shadow the passed-in `selection` to avoid | ||
// leaking changes to it via a 2-way binding | ||
_selection: reads('selection'), | ||
|
||
actions: { | ||
change() { | ||
// jscs:disable requireArrayDestructuring | ||
let selectEl = this.$('select')[0]; | ||
// jscs:enable requireArrayDestructuring | ||
let {selectedIndex} = selectEl; | ||
|
||
// decrement index by 1 if we have a prompt | ||
let hasPrompt = !!this.get('prompt'); | ||
let contentIndex = hasPrompt ? selectedIndex - 1 : selectedIndex; | ||
|
||
let selection = this.get('content').objectAt(contentIndex); | ||
|
||
// set the local, shadowed selection to avoid leaking | ||
// changes to `selection` out via 2-way binding | ||
this.set('_selection', selection); | ||
|
||
this.sendAction('action', selection); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* jshint expr:true */ | ||
import {expect} from 'chai'; | ||
import { | ||
describeComponent, | ||
it | ||
} from 'ember-mocha'; | ||
|
||
describeComponent( | ||
'gh-select-native', | ||
'Unit: Component: gh-select-native', | ||
{ | ||
unit: true | ||
// specify the other units that are required for this test | ||
// needs: ['component:foo', 'helper:bar'] | ||
}, | ||
function () { | ||
it('renders', function () { | ||
// creates the component instance | ||
let component = this.subject(); | ||
|
||
expect(component._state).to.equal('preRender'); | ||
|
||
// renders the component on the page | ||
this.render(); | ||
expect(component._state).to.equal('inDOM'); | ||
}); | ||
} | ||
); |