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

support passing HTML attributes to <PowerSelect> #89

Merged
merged 1 commit into from
Sep 13, 2019
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
@@ -1,68 +1,71 @@
{{#component this.powerSelectComponent
afterOptionsComponent=@afterOptionsComponent
allowClear=@allowClear
animationEnabled=@animationEnabled
ariaDescribedBy=this.ariaDescribedBy
ariaInvalid=@ariaInvalid
ariaLabel=@ariaLabel
ariaLabelledBy=@ariaLabelledBy
beforeOptionsComponent=@beforeOptionsComponent
buildSelection=@buildSelection
calculatePosition=@calculatePosition
class=@class
closeOnSelect=@closeOnSelect
defaultHighlighted=@defaultHighlighted
destination=@destination
disabled=@disabled
dropdownClass=@dropdownClass
eventType=@eventType
extra=@extra
groupComponent=@groupComponent
highlightOnHover=@highlightOnHover
horizontalPosition=@horizontalPosition
initiallyOpened=@initiallyOpened
loadingMessage=@loadingMessage
matcher=@matcher
matchTriggerWidth=@matchTriggerWidth
noMatchesMessage=@noMatchesMessage
onBlur=@onBlur
onChange=(action this.onChange)
onClose=@onClose
onFocus=@onFocus
onInput=@onInput
onKeyDown=@onKeyDown
onOpen=@onOpen
options=@options
optionsComponent=@optionsComponent
placeholder=@placeholder
placeholderComponent=@placeholderComponent
preventScroll=@preventScroll
registerAPI=@registerAPI
renderInPlace=@renderInPlace
scrollTo=@scrollTo
search=@search
searchEnabled=@searchEnabled
searchField=(if hasBlock @searchField (if @searchField @searchField @optionLabelPath))
searchMessage=@searchMessage
searchPlaceholder=@searchPlaceholder
selected=this.value
selectedItemComponent=@selectedItemComponent
tabindex=@tabindex
triggerClass=@triggerClass
triggerComponent=@triggerComponent
triggerId=@triggerId
triggerRole=@triggerRole
typeAheadMatcher=@typeAheadMatcher
verticalPosition=@verticalPosition
as |item select|
}}
{{#if hasBlock}}
{{yield item select}}
{{else}}
{{#if @optionLabelPath}}
{{get item @optionLabelPath}}
{{#let (component this.powerSelectComponent) as |PowerSelect|}}
<PowerSelect
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach was discussed here: emberjs/rfcs#497

@afterOptionsComponent={{@afterOptionsComponent}}
@allowClear={{@allowClear}}
@animationEnabled={{@animationEnabled}}
@ariaDescribedBy={{this.ariaDescribedBy}}
@ariaInvalid={{@ariaInvalid}}
@ariaLabel={{@ariaLabel}}
@ariaLabelledBy={{@ariaLabelledBy}}
@beforeOptionsComponent={{@beforeOptionsComponent}}
@buildSelection={{@buildSelection}}
@calculatePosition={{@calculatePosition}}
@class={{@class}}
@closeOnSelect={{@closeOnSelect}}
@defaultHighlighted={{@defaultHighlighted}}
@destination={{@destination}}
@disabled={{@disabled}}
@dropdownClass={{@dropdownClass}}
@eventType={{@eventType}}
@extra={{@extra}}
@groupComponent={{@groupComponent}}
@highlightOnHover={{@highlightOnHover}}
@horizontalPosition={{@horizontalPosition}}
@initiallyOpened={{@initiallyOpened}}
@loadingMessage={{@loadingMessage}}
@matcher={{@matcher}}
@matchTriggerWidth={{@matchTriggerWidth}}
@noMatchesMessage={{@noMatchesMessage}}
@onBlur={{@onBlur}}
@onChange={{action this.onChange}}
@onClose={{@onClose}}
@onFocus={{@onFocus}}
@onInput={{@onInput}}
@onKeyDown={{@onKeyDown}}
@onOpen={{@onOpen}}
@options={{@options}}
@optionsComponent={{@optionsComponent}}
@placeholder={{@placeholder}}
@placeholderComponent={{@placeholderComponent}}
@preventScroll={{@preventScroll}}
@registerAPI={{@registerAPI}}
@renderInPlace={{@renderInPlace}}
@scrollTo={{@scrollTo}}
@search={{@search}}
@searchEnabled={{@searchEnabled}}
@searchField={{if hasBlock @searchField (if @searchField @searchField @optionLabelPath)}}
@searchMessage={{@searchMessage}}
@searchPlaceholder={{@searchPlaceholder}}
@selected={{this.value}}
@selectedItemComponent={{@selectedItemComponent}}
@tabindex={{@tabindex}}
@triggerClass={{@triggerClass}}
@triggerComponent={{@triggerComponent}}
@triggerId={{@triggerId}}
@triggerRole={{@triggerRole}}
@typeAheadMatcher={{@typeAheadMatcher}}
@verticalPosition={{@verticalPosition}}
...attributes
as |item select|
>
{{#if hasBlock}}
{{yield item select}}
{{else}}
{{item}}
{{#if @optionLabelPath}}
{{get item @optionLabelPath}}
{{else}}
{{item}}
{{/if}}
{{/if}}
{{/if}}
{{/component}}
</PowerSelect>
{{/let}}
135 changes: 69 additions & 66 deletions addon/templates/components/bs-form/element/control/power-select.hbs
Original file line number Diff line number Diff line change
@@ -1,68 +1,71 @@
{{#component this.powerSelectComponent
afterOptionsComponent=@afterOptionsComponent
allowClear=@allowClear
animationEnabled=@animationEnabled
ariaDescribedBy=this.ariaDescribedBy
ariaInvalid=@ariaInvalid
ariaLabel=@ariaLabel
ariaLabelledBy=@ariaLabelledBy
beforeOptionsComponent=@beforeOptionsComponent
buildSelection=@buildSelection
calculatePosition=@calculatePosition
class=@class
closeOnSelect=@closeOnSelect
defaultHighlighted=@defaultHighlighted
destination=@destination
disabled=@disabled
dropdownClass=@dropdownClass
eventType=@eventType
extra=@extra
groupComponent=@groupComponent
highlightOnHover=@highlightOnHover
horizontalPosition=@horizontalPosition
initiallyOpened=@initiallyOpened
loadingMessage=@loadingMessage
matcher=@matcher
matchTriggerWidth=@matchTriggerWidth
noMatchesMessage=@noMatchesMessage
onBlur=@onBlur
onChange=(action this.onChange)
onClose=@onClose
onFocus=@onFocus
onInput=@onInput
onKeyDown=@onKeyDown
onOpen=@onOpen
options=@options
optionsComponent=@optionsComponent
placeholder=@placeholder
placeholderComponent=@placeholderComponent
preventScroll=@preventScroll
registerAPI=@registerAPI
renderInPlace=@renderInPlace
scrollTo=@scrollTo
search=@search
searchEnabled=@searchEnabled
searchField=(if hasBlock @searchField (if @searchField @searchField @optionLabelPath))
searchMessage=@searchMessage
searchPlaceholder=@searchPlaceholder
selected=this.value
selectedItemComponent=@selectedItemComponent
tabindex=@tabindex
triggerClass=@triggerClass
triggerComponent=@triggerComponent
triggerId=@triggerId
triggerRole=@triggerRole
typeAheadMatcher=@typeAheadMatcher
verticalPosition=@verticalPosition
as |item select|
}}
{{#if hasBlock}}
{{yield item select}}
{{else}}
{{#if @optionLabelPath}}
{{get item @optionLabelPath}}
{{#let (component this.powerSelectComponent) as |PowerSelect|}}
<PowerSelect
@afterOptionsComponent={{@afterOptionsComponent}}
@allowClear={{@allowClear}}
@animationEnabled={{@animationEnabled}}
@ariaDescribedBy={{this.ariaDescribedBy}}
@ariaInvalid={{@ariaInvalid}}
@ariaLabel={{@ariaLabel}}
@ariaLabelledBy={{@ariaLabelledBy}}
@beforeOptionsComponent={{@beforeOptionsComponent}}
@buildSelection={{@buildSelection}}
@calculatePosition={{@calculatePosition}}
@class={{@class}}
@closeOnSelect={{@closeOnSelect}}
@defaultHighlighted={{@defaultHighlighted}}
@destination={{@destination}}
@disabled={{@disabled}}
@dropdownClass={{@dropdownClass}}
@eventType={{@eventType}}
@extra={{@extra}}
@groupComponent={{@groupComponent}}
@highlightOnHover={{@highlightOnHover}}
@horizontalPosition={{@horizontalPosition}}
@initiallyOpened={{@initiallyOpened}}
@loadingMessage={{@loadingMessage}}
@matcher={{@matcher}}
@matchTriggerWidth={{@matchTriggerWidth}}
@noMatchesMessage={{@noMatchesMessage}}
@onBlur={{@onBlur}}
@onChange={{action this.onChange}}
@onClose={{@onClose}}
@onFocus={{@onFocus}}
@onInput={{@onInput}}
@onKeyDown={{@onKeyDown}}
@onOpen={{@onOpen}}
@options={{@options}}
@optionsComponent={{@optionsComponent}}
@placeholder={{@placeholder}}
@placeholderComponent={{@placeholderComponent}}
@preventScroll={{@preventScroll}}
@registerAPI={{@registerAPI}}
@renderInPlace={{@renderInPlace}}
@scrollTo={{@scrollTo}}
@search={{@search}}
@searchEnabled={{@searchEnabled}}
@searchField={{if hasBlock @searchField (if @searchField @searchField @optionLabelPath)}}
@searchMessage={{@searchMessage}}
@searchPlaceholder={{@searchPlaceholder}}
@selected={{this.value}}
@selectedItemComponent={{@selectedItemComponent}}
@tabindex={{@tabindex}}
@triggerClass={{@triggerClass}}
@triggerComponent={{@triggerComponent}}
@triggerId={{@triggerId}}
@triggerRole={{@triggerRole}}
@typeAheadMatcher={{@typeAheadMatcher}}
@verticalPosition={{@verticalPosition}}
...attributes
as |item select|
>
{{#if hasBlock}}
{{yield item select}}
{{else}}
{{item}}
{{#if @optionLabelPath}}
{{get item @optionLabelPath}}
{{else}}
{{item}}
{{/if}}
{{/if}}
{{/if}}
{{/component}}
</PowerSelect>
{{/let}}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,15 @@ module('Integration | Component | bs form/element/control/power select multiple'
await clickTrigger();
assert.dom('.ember-power-select-search-input').doesNotExist();
});

test('it passes HTML attributes', async function(assert) {
// HTML attributes are not applied to any element if `renderInPlace` is `false`
await render(hbs`
<BsForm @model={{hash}} as |form|>
<form.element @controlType="power-select-multiple" @property="prop" @options={{array}} as |el|>
<el.control @renderInPlace={{true}} data-test-foo />
</form.element>
</BsForm>`);
assert.dom('[data-test-foo]').exists();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,22 @@ module('Integration | Component | bs form/element/control/power select', functio
await render(hbs`
<BsForm @model={{this}} as |form|>
<form.element @controlType="power-select" @property="prop2" @options={{options}} @placeholder="something" as |el|>
{{el.control searchEnabled=false triggerClass='form-control' }}
<el.control @searchEnabled={{false}} @triggerClass="form-control" />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really related to this PR but missed in #86.

</form.element>
</BsForm>`);
assert.dom('.form-control').exists();
await clickTrigger();
assert.dom('.ember-power-select-search-input').doesNotExist();
});

test('it passes HTML attributes', async function(assert) {
// HTML attributes are not applied to any element if `renderInPlace` is `false`
await render(hbs`
<BsForm @model={{hash}} as |form|>
<form.element @controlType="power-select" @property="prop" @options={{array}} as |el|>
<el.control @renderInPlace={{true}} data-test-foo />
</form.element>
</BsForm>`);
assert.dom('[data-test-foo]').exists();
});
});