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

Save progress on a spike for a lower-level API #1310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
522 changes: 522 additions & 0 deletions addon/components/basic-select.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions addon/components/basic-select/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Component from '@glimmer/component';

export default class BasicSelectContent extends Component {
}
4 changes: 4 additions & 0 deletions addon/components/basic-select/trigger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Component from '@glimmer/component';

export default class BasicSelectTrigger extends Component {
}
2 changes: 1 addition & 1 deletion addon/components/power-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export default class PowerSelect extends Component {
if (match !== undefined) {
if (this.storedAPI.isOpen) {
this.storedAPI.actions.highlight(match, e);
this.storedAPI.actions.scrollTo(match, e);
this.storedAPI.actions.scrollTo(match, this.storedAPI, e);
} else {
this.storedAPI.actions.select(match, e);
}
Expand Down
2 changes: 1 addition & 1 deletion addon/components/power-select/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class Options extends Component {
});
}
if (role !== 'group') {
this.args.select.actions.scrollTo(this.args.select.highlighted);
this.args.select.actions.scrollTo(this.args.select.highlighted, this.args.select);
}
}

Expand Down
50 changes: 50 additions & 0 deletions addon/templates/components/basic-select.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<BasicDropdown
@horizontalPosition={{@horizontalPosition}}
@destination={{@destination}}
@initiallyOpened={{@initiallyOpened}}
@matchTriggerWidth={{this.matchTriggerWidth}}
@preventScroll={{or @preventScroll false}}
@onClose={{this.handleClose}}
@onOpen={{this.handleOpen}}
@renderInPlace={{@renderInPlace}}
@verticalPosition={{@verticalPosition}}
@disabled={{@disabled}}
@calculatePosition={{@calculatePosition}}
...attributes as |dropdown|>
{{#let (assign dropdown (hash
selected=this.selected
highlighted=this.highlighted
options=this.options
results=this.results
resultsCount=this.resultsCount
loading=this.loading
isActive=this.isActive
searchText=this.searchText
lastSearchedText=this.lastSearchedText
actions=(assign dropdown.actions this._publicAPIActions)
)) (concat "ember-power-select-options-" dropdown.uniqueId) as |select listboxId|}}
{{#let (assign select (
hash
Trigger=(
component
"basic-select/trigger"
select=select
Trigger=(component "power-select/trigger" select=select)
)
Content=(
component
"basic-select/content"
select=select
)
Options=(
component
"power-select/options"
select=select
options=select.results
groupIndex=""
)
)) as |publicAPI|}}
{{yield publicAPI}}
{{/let}}
{{/let}}
</BasicDropdown>
3 changes: 3 additions & 0 deletions addon/templates/components/basic-select/content.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<@select.Content>
{{yield}}
</@select.Content>
30 changes: 30 additions & 0 deletions addon/templates/components/basic-select/trigger.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<@select.Trigger class="ember-power-select-trigger"
{{!-- @eventType={{or @eventType "mousedown"}}
{{did-insert this._updateOptions @options}}
{{did-update this._updateOptions @options}}
{{did-insert this._updateSelected @selected}}
{{did-update this._updateSelected @selected}}
{{did-update this._registerAPI publicAPI}}
{{did-update this._performSearch this.searchText}}
{{on "keydown" this.handleTriggerKeydown}}
{{on "focus" this.handleFocus}}
{{on "blur" this.handleBlur}}
class="ember-power-select-trigger {{@triggerClass}}{{if publicAPI.isActive " ember-power-select-trigger--active"}}"
aria-describedby={{@ariaDescribedBy}}
aria-invalid={{@ariaInvalid}}
aria-label={{@ariaLabel}}
aria-labelledby={{@ariaLabelledBy}}
aria-required={{@required}}
role={{or @triggerRole "button"}}
title={{@title}}
id={{@triggerId}}
tabindex={{and (not @disabled) (or @tabindex "0")}} --}}
>
<@Trigger as |opt term|>
{{#if (has-block)}}
{{yield opt term}}
{{else}}
{{opt}}
{{/if}}
</@Trigger>
</@select.Trigger>
1 change: 1 addition & 0 deletions app/components/basic-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-power-select/components/basic-select';
1 change: 1 addition & 0 deletions app/components/basic-select/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-power-select/components/basic-select/content';
1 change: 1 addition & 0 deletions app/components/basic-select/trigger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-power-select/components/basic-select/trigger';
1 change: 1 addition & 0 deletions app/templates/components/basic-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-power-select/templates/components/basic-select';
1 change: 1 addition & 0 deletions app/templates/components/basic-select/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-power-select/templates/components/basic-select/content';
1 change: 1 addition & 0 deletions app/templates/components/basic-select/trigger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-power-select/templates/components/basic-select/trigger';
14 changes: 14 additions & 0 deletions tests/dummy/app/templates/playground.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@
{{city}}
</PowerSelect>

<h3>Example of basic-select</h3>
<BasicSelect
@options={{this.cities}}
@selected={{this.destination}}
@onChange={{fn (mut this.destination)}} as |select|>
<select.Trigger as |opt|>
{{opt}}
</select.Trigger>
<select.Content>
<select.Options as |option select|>
{{option}}
</select.Options>
</select.Content>
</BasicSelect>
26 changes: 26 additions & 0 deletions tests/integration/components/basic-select-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | basic-select', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`<BasicSelect />`);

assert.equal(this.element.textContent.trim(), '');

// Template block usage:
await render(hbs`
<BasicSelect>
template block text
</BasicSelect>
`);

assert.equal(this.element.textContent.trim(), 'template block text');
});
});
26 changes: 26 additions & 0 deletions tests/integration/components/basic-select/content-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | basic-select/content', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`<BasicSelect::Content />`);

assert.equal(this.element.textContent.trim(), '');

// Template block usage:
await render(hbs`
<BasicSelect::Content>
template block text
</BasicSelect::Content>
`);

assert.equal(this.element.textContent.trim(), 'template block text');
});
});
26 changes: 26 additions & 0 deletions tests/integration/components/basic-select/trigger-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | basic-select/trigger', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`<BasicSelect::Trigger />`);

assert.equal(this.element.textContent.trim(), '');

// Template block usage:
await render(hbs`
<BasicSelect::Trigger>
template block text
</BasicSelect::Trigger>
`);

assert.equal(this.element.textContent.trim(), 'template block text');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ module('Integration | Component | Ember Power Select (Public actions)', function
</PowerSelect>
`);

run(() => this.selectAPI.actions.scrollTo('three'));
run(() => this.selectAPI.actions.scrollTo('three', this.selectAPI));
});

test('The given `scrollTo` function is invoked when a multiple select wants to scroll to an element', async function(assert) {
Expand All @@ -684,7 +684,7 @@ module('Integration | Component | Ember Power Select (Public actions)', function
</PowerSelectMultiple>
`);

run(() => this.selectAPI.actions.scrollTo('three'));
run(() => this.selectAPI.actions.scrollTo('three', this.selectAPI));
});
});