Skip to content

Commit

Permalink
add dropdown content destination argument
Browse files Browse the repository at this point in the history
  • Loading branch information
amk221 committed Jan 17, 2025
1 parent e1d15c5 commit 7648f72
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ A combobox, which toggles the select box's dropdown open/closed.

An element to house the content that displays when the select box's dropdown is opened

#### `@destination`

Optional. Wormhole/Portal element

## `Dropdown`

### Arguments
Expand Down
28 changes: 20 additions & 8 deletions addon/components/dropdown/content.gjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import lifecycle from '@zestia/ember-select-box/modifiers/lifecycle';

const Destination = <template>
{{#if @destination}}
{{#in-element @destination insertBefore=null}}
{{yield}}
{{/in-element}}
{{else}}
{{yield}}
{{/if}}
</template>;

<template>
{{! template-lint-disable no-positive-tabindex }}
<div
class="dropdown__content"
tabindex={{@tabindex}}
{{lifecycle onInsert=@onInsert onDestroy=@onDestroy}}
...attributes
>
{{yield}}
</div>
<Destination @destination={{@destination}}>
<div
class="dropdown__content"
tabindex={{@tabindex}}
{{lifecycle onInsert=@onInsert onDestroy=@onDestroy}}
...attributes
>
{{yield}}
</div>
</Destination>
</template>
1 change: 1 addition & 0 deletions addon/components/dropdown/index.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export default class Dropdown extends Component {
)
Content=(component
DropdownContent
destination=this.element
onFocusOut=this.handleFocusOutContent
onMouseDown=this.handleMouseDownContent
onInsert=this.handleInsertContent
Expand Down
10 changes: 4 additions & 6 deletions tests/integration/components/dropdown/index/in-element-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ module('dropdown (in-element)', function (hooks) {
Trigger
</dd.Trigger>
{{#if dd.isOpen}}
{{#in-element (destination) insertBefore=null}}
<dd.Content>
Hello World
<button type="button" class="test" />
</dd.Content>
{{/in-element}}
<dd.Content @destination={{(destination)}}>
Hello World
<button type="button" class="test" />
</dd.Content>
{{/if}}
</Dropdown>

Expand Down
16 changes: 6 additions & 10 deletions tests/integration/components/select-box/index/in-element-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ module('select-box (in-element)', function (hooks) {
<sb.Trigger>
{{sb.value}}
</sb.Trigger>
{{#if dd.isOpen}}
{{#in-element (destination) insertBefore=null}}
<sb.Content>
<sb.Options>
<sb.Option @value="foo" />
<sb.Option @value="bar" />
</sb.Options>
</sb.Content>
{{/in-element}}
{{/if}}
<sb.Content @destination={{(destination)}}>
<sb.Options>
<sb.Option @value="foo" />
<sb.Option @value="bar" />
</sb.Options>
</sb.Content>
</sb.Dropdown>
</SelectBox>

Expand Down

0 comments on commit 7648f72

Please sign in to comment.