Skip to content

Commit

Permalink
refactor(cxl-ui): cxl-marketing-nav support `vaadin-tab.current-menu-…
Browse files Browse the repository at this point in the history
…item`, fix #42

Close #45
  • Loading branch information
freudFlintstone authored and lkraav committed Apr 12, 2020
1 parent 7e99744 commit e830f1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/cxl-ui/src/components/cxl-marketing-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class CXLMarketingNavElement extends LitElement {
updated(changedProps) {
if (changedProps.has('contextMenuItems')) {
this._updatedContextMenuItems();
this._updatedSelectCurrentTab()
}

if (changedProps.has('wide')) {
Expand Down Expand Up @@ -222,6 +223,20 @@ export class CXLMarketingNavElement extends LitElement {
return contextMenuItems;
}

/**
* The can't have a default selection. WordPress provides a `current-menu-item` class for the current item
* This sets `selected` attribute for with that tab index when menu items are ready. Happens once.
* @private
*/
_updatedSelectCurrentTab() {
const currentTab = this.querySelector('.current-menu-item');
if (currentTab && currentTab.id) {
const tabsContainer = currentTab.parentElement;
const idx = tabsContainer.items.findIndex(i => i.id === currentTab.id);
tabsContainer.selected = idx;
}
}

/**
* Populate children `<vaadin-context-menu>` elements.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook/cxl-ui/cxl-marketing-nav.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const CxlMarketingNav = () => {
><iron-icon icon="cxl:logo" style="width: var(--lumo-icon-size-xl, 48px);"></iron-icon
></a>
</vaadin-tab>
<vaadin-tab class="menu-item" theme="cxl-marketing-nav"
<vaadin-tab id="menu-item-94" class="current-menu-item menu-item menu-item-94" theme="cxl-marketing-nav"
><a href="https://conversionxl.com/institute/">Institute</a></vaadin-tab
>
<vaadin-tab
Expand Down

0 comments on commit e830f1d

Please sign in to comment.