Skip to content

Commit 3e4ae20

Browse files
authored
Backport @triggerHtmlTag and add workaround to resolve button typing issue (#1033)
1 parent 3b808e0 commit 3e4ae20

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

docs/app/templates/public-pages.gts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,16 @@ export default class extends Component {
7474
>Github</a>
7575
</div>
7676
<div class="main-header-logo">
77-
<BasicDropdown @calculatePosition={{this.calculatePosition}} as |dd|>
77+
<BasicDropdown
78+
@triggerHtmlTag="span"
79+
@calculatePosition={{this.calculatePosition}}
80+
as |dd|
81+
>
7882
<LinkTo @route="public-pages.index" class="home-link">
7983
<img src="/ember_logo.png" alt="ember" />
8084
<strong>Basic</strong>
8185
{{! template-lint-disable no-pointer-down-event-binding }}
8286
<dd.Trigger
83-
@htmlTag="span"
8487
{{on "mousedown" this.preventIfNotInIndex}}
8588
{{on "touchend" this.preventIfNotInIndex}}
8689
class="logo-dropdown-button"

ember-basic-dropdown/src/components/basic-dropdown-trigger.gts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { Dropdown } from './basic-dropdown';
1010
import type { HorizontalPosition, VerticalPosition } from '../types.ts';
1111

1212
export interface BasicDropdownTriggerSignature {
13-
Element: HTMLElement;
13+
Element: HTMLElement | HTMLButtonElement;
1414
Args: {
1515
dropdown?: Dropdown;
1616
eventType?: 'click' | 'mousedown';
@@ -19,7 +19,7 @@ export interface BasicDropdownTriggerSignature {
1919
hPosition?: HorizontalPosition | null;
2020
defaultClass?: string;
2121
renderInPlace?: boolean;
22-
htmlTag?: keyof HTMLElementTagNameMap;
22+
htmlTag?: keyof HTMLElementTagNameMap | undefined;
2323
onBlur?: (dropdown?: Dropdown, event?: FocusEvent) => void;
2424
onClick?: (dropdown?: Dropdown, event?: MouseEvent) => void;
2525
onFocus?: (dropdown?: Dropdown, event?: FocusEvent) => void;

ember-basic-dropdown/src/components/basic-dropdown.gts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface BasicDropdownArgs {
6565
rootEventType?: TRootEventType;
6666
preventScroll?: boolean;
6767
matchTriggerWidth?: boolean;
68+
triggerHtmlTag?: keyof HTMLElementTagNameMap;
6869
onInit?: (dropdown: Dropdown) => void;
6970
registerAPI?: (dropdown: Dropdown | null) => void;
7071
onOpen?: (dropdown: Dropdown, e?: Event) => boolean | void;
@@ -533,6 +534,7 @@ export default class BasicDropdown extends Component<BasicDropdownSignature> {
533534
hPosition=this.hPosition
534535
renderInPlace=this.renderInPlace
535536
vPosition=this.vPosition
537+
htmlTag=@triggerHtmlTag
536538
)
537539
Content=(component
538540
this.contentComponent

test-app/tests/integration/components/basic-dropdown-test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,22 +1133,22 @@ module('Integration | Component | basic-dropdown', function (hooks) {
11331133
assert.expect(12);
11341134

11351135
await render(hbs`
1136-
<BasicDropdown as |parent|>
1137-
<parent.Trigger class='parent' @htmlTag="button">Trigger of the first dropdown</parent.Trigger>
1136+
<BasicDropdown @triggerHtmlTag="button" as |parent|>
1137+
<parent.Trigger class='parent'>Trigger of the first dropdown</parent.Trigger>
11381138
<parent.Content @overlay={{true}}>
1139-
<BasicDropdown as |child|>
1139+
<BasicDropdown @triggerHtmlTag="button" as |child|>
11401140
<p class="body-parent">
11411141
<br>First level of the dropdpwn<br>
11421142
</p>
1143-
<child.Trigger class='child' @htmlTag="button">Trigger of the second dropdown</child.Trigger>
1143+
<child.Trigger class='child'>Trigger of the second dropdown</child.Trigger>
11441144
<child.Content @overlay={{true}}>
11451145
<p class="body-child">
11461146
<br>Second level of the second<br>
1147-
<BasicDropdown as |grandchild|>
1147+
<BasicDropdown @triggerHtmlTag="button" as |grandchild|>
11481148
<p>
11491149
<br>Second level of the dropdpwn<br>
11501150
</p>
1151-
<grandchild.Trigger class='grandchild' @htmlTag="button">Trigger of the Third dropdown</grandchild.Trigger>
1151+
<grandchild.Trigger class='grandchild'>Trigger of the Third dropdown</grandchild.Trigger>
11521152
<grandchild.Content @overlay={{true}}>
11531153
<p class="body-grandchild">
11541154
<br>Third level of the third<br>

0 commit comments

Comments
 (0)