Skip to content

Commit

Permalink
fix(menu): map deprecated icon property to leadingIcon when optio…
Browse files Browse the repository at this point in the history
…ns are loaded from factory (#461)
  • Loading branch information
eliganemtyler authored Feb 15, 2024
1 parent 96a9b85 commit 70b6912
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/menu/menu-foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export class MenuFoundation extends CascadingListDropdownAwareFoundation<IMenuOp
if (this._open) {
if (results && isArray(results) && results.length) {
this._options = results;
this._mapIconToLeadingIcon();
this._adapter.setOptions(results);
const selectedValues = this._getSelectedValues();
if (selectedValues.length) {
Expand Down
25 changes: 25 additions & 0 deletions src/test/spec/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IPopupComponent,
LIST_ITEM_CONSTANTS,
MENU_CONSTANTS,
MenuOptionFactory,
POPUP_CONSTANTS
} from '@tylertech/forge';
import { getShadowElement, removeElement } from '@tylertech/forge-core';
Expand Down Expand Up @@ -428,6 +429,30 @@ describe('MenuComponent', function(this: ITestContext) {
expect(leadingIconEl).toBeTruthy();
expect(leadingIconEl?.textContent).toBe('code');
});

it(`should load leading icons from options factory based on 'leadingIcon' or 'icon' property`, async function(this: ITestContext){
this.context = setupTestContext();
const options: MenuOptionFactory = () => {
return [
{ icon: 'code', value: '', label: '1' },
{ leadingIcon: 'code', value: '', label: '2' }
];
}

await tick();

this.context.component.options = options;
this.context.component.open = true;

await tick();

const list = getPopupList(getPopupElement());
const listItems = Array.from(list.querySelectorAll(LIST_ITEM_CONSTANTS.elementName)) as IListItemComponent[];
const leadingIcons = listItems.map(listItem => listItem.querySelector('i[slot=leading]'));

expect(leadingIcons[0]).toBeTruthy();
expect(leadingIcons[1]).toBeTruthy();
});
});

describe(`events`, function(this: ITestContext) {
Expand Down

0 comments on commit 70b6912

Please sign in to comment.