Skip to content

Commit

Permalink
Pass destinationElement to basic-dropdown (#1863)
Browse files Browse the repository at this point in the history
ember-basic-dropdown accepts `destinationElement` argument and
power-select should to support it as well.
  • Loading branch information
andreyfel authored Dec 4, 2024
1 parent d5e014f commit 77e1fce
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@highlightOnHover={{@highlightOnHover}}
@typeAheadOptionMatcher={{@typeAheadOptionMatcher}}
@destination={{@destination}}
@destinationElement={{@destinationElement}}
@disabled={{@disabled}}
@dropdownClass={{@dropdownClass}}
@extra={{@extra}}
Expand Down
1 change: 1 addition & 0 deletions ember-power-select/src/components/power-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{{/if}}
<BasicDropdown
@horizontalPosition={{@horizontalPosition}}
@destinationElement={{@destinationElement}}
@destination={{@destination}}
@initiallyOpened={{@initiallyOpened}}
@matchTriggerWidth={{this.matchTriggerWidth}}
Expand Down
1 change: 1 addition & 0 deletions ember-power-select/src/components/power-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface PowerSelectArgs {
options?: readonly any[] | Promise<readonly any[]>;
selected?: any | PromiseProxy<any>;
destination?: string;
destinationElement?: HTMLElement;
closeOnSelect?: boolean;
renderInPlace?: boolean;
preventScroll?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
import ArrayProxy from '@ember/array/proxy';
import ObjectProxy from '@ember/object/proxy';
import { TrackedArray } from 'tracked-built-ins';
import { modifier } from 'ember-modifier';

const PromiseArrayProxy = ArrayProxy.extend(PromiseProxyMixin);
const PromiseObject = ObjectProxy.extend(PromiseProxyMixin);
Expand Down Expand Up @@ -1385,6 +1386,30 @@ module(
.exists('Dropdown is rendered inside the destination element');
});

test('The destination where the content is rendered can be customized by passing a `destinationElement=element`', async function (assert) {
assert.expect(2);

this.numbers = numbers;
this.ref = modifier((element) => {
this.set('destinationElement', element);
});
await render(hbs`
<PowerSelect @options={{this.numbers}} @onChange={{fn (mut this.foo)}} @destinationElement={{this.destinationElement}} as |option|>
{{option}}
</PowerSelect>
<div class="alternative-destination" {{this.ref}}></div>
`);

assert
.dom('.ember-power-select-dropdown')
.doesNotExist('Dropdown is not rendered');

await clickTrigger();
assert
.dom('.alternative-destination .ember-power-select-dropdown')
.exists('Dropdown is rendered inside the destination element');
});

test('[BUGFIX] When the component is open and it has a `search` action, if options get updated the highlighted items is reset', async function (assert) {
assert.expect(2);

Expand Down

0 comments on commit 77e1fce

Please sign in to comment.