1+ import { tracked } from " @glimmer/tracking" ;
12import Component from " @ember/component" ;
23import { fn } from " @ember/helper" ;
34import { on } from " @ember/modifier" ;
45import { action } from " @ember/object" ;
56import { notEmpty } from " @ember/object/computed" ;
6- import { inject as service } from " @ember/service" ;
7+ import { service } from " @ember/service" ;
8+ import { and , not } from " truth-helpers" ;
79import concatClass from " discourse/helpers/concat-class" ;
10+ import dIcon from " discourse/helpers/d-icon" ;
811import DiscourseURL from " discourse/lib/url" ;
9- import dIcon from " discourse-common/helpers/d-icon" ;
1012import CustomIcon from " ./custom-icon" ;
1113
1214export default class CustomHeaderLink extends Component {
1315 @service siteSettings;
1416 @service site;
1517 @service currentUser;
1618
19+ @tracked dropdownOpen = true ;
20+
1721 @notEmpty (" dropdownLinks" ) hasDropdown;
1822
1923 get shouldDisplay () {
@@ -48,7 +52,11 @@ export default class CustomHeaderLink extends Component {
4852 }
4953
5054 get showCaret () {
51- return settings .show_caret_icons && this .hasDropdown ;
55+ return (
56+ settings .show_caret_icons &&
57+ this .hasDropdown &&
58+ (! this .site .mobileView || ! this .item .url )
59+ );
5260 }
5361
5462 get dropdownLinks () {
@@ -64,7 +72,12 @@ export default class CustomHeaderLink extends Component {
6472 }
6573
6674 @action
67- redirectToUrl (item ) {
75+ toggleDropdown () {
76+ this .dropdownOpen = ! this .dropdownOpen ;
77+ }
78+
79+ @action
80+ redirectToUrl (item , event ) {
6881 if (this .site .mobileView ) {
6982 this .toggleHeaderLinks ();
7083 }
@@ -85,9 +98,14 @@ export default class CustomHeaderLink extends Component {
8598 " custom-header-link"
8699 ( if @ item.url " with-url" )
87100 ( if this . hasDropdown " has-dropdown" )
101+ ( if this . dropdownOpen " is-open" )
88102 }}
89103 title ={{@ item.title }}
90104 {{( if @ item.url ( modifier on " click" ( fn this . redirectToUrl @ item) ))}}
105+ {{( if
106+ ( and ( not @ item.url) this . site.mobileView this . hasDropdown)
107+ ( modifier on " click" this . toggleDropdown)
108+ )}}
91109 >
92110 <CustomIcon @ icon ={{@ item.icon }} />
93111 <span class =" custom-header-link-title" >{{@ item.title }} </span >
0 commit comments