Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(card): Card can not expand nested overlay-menu in touch devices #623

Merged
merged 6 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion packages/elements/src/card/__test__/card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '@formatjs/intl-pluralrules/locale-data/en';
import '@refinitiv-ui/elements/card';
import '@refinitiv-ui/elemental-theme/light/ef-card';

const menuData = [{ label: 'Spain', value: 'Spain' }, { label: 'France',value: 'France', disabled: true }, { label: 'Italy', value: 'Italy' }];
const menuData = [{ label: 'Spain', value: 'Spain' }, { label: 'France',value: 'France', disabled: true }, { label: 'Italy', value: 'Italy' }, { label: 'Other', items: [{ label: 'Thailand', value: 'Thailand' }] }];

describe('card/Card', () => {
describe('DOM structure', () => {
Expand Down Expand Up @@ -82,6 +82,36 @@ describe('card/Card', () => {
await oneEvent(el, 'item-trigger');
expect(menu.opened).to.equal(false, 'Menu should close when item is selected');
});
it('Should open menu and not close when clicked on non value item', async () => {
wattachai-lseg marked this conversation as resolved.
Show resolved Hide resolved
const el = await fixture('<ef-card lang="en-gb">Card</ef-card>');
el.config = {
menu: {
data: menuData
}
};
await elementUpdated(el);

const openMenu = el.openMenuElement;
const menu = el.menuElement;

expect(openMenu, 'Open menu button element does not exist').to.exist;
expect(menu, 'Menu element does not exist').to.exist;

openMenu.click();

await elementUpdated(el);
expect(menu.opened).to.equal(true, 'Menu should open on button click');

const item = menu.shadowRoot.querySelectorAll('ef-item')[3];

expect(item, 'Menu config is not passed correctly').to.exist;

setTimeout(() => {
item.click();
});
await oneEvent(el, 'item-trigger');
expect(menu.opened).to.equal(true, 'Menu should still open');
});
});

describe('Accessibility', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/elements/src/card/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { isSlotEmpty } from '@refinitiv-ui/utils/is-slot-empty.js';
import type { Button } from '../button';
import type { OverlayMenu, OverlayMenuData } from '../overlay-menu';
import type { CardConfig } from './helpers/types';
import type { OpenedChangedEvent } from '../events';
import type { OpenedChangedEvent, ItemTriggerEvent } from '../events';
import '../label/index.js';
import '../button/index.js';
import '../overlay-menu/index.js';
Expand Down Expand Up @@ -155,10 +155,11 @@ export class Card extends BasicElement {

/**
* Close menu
* @param event Custom event
Nantawat-Poothong marked this conversation as resolved.
Show resolved Hide resolved
* @returns {void}
*/
private closeMenu (): void {
if (this.menuElement?.opened) {
private closeMenu (event: ItemTriggerEvent): void {
if (this.menuElement?.opened && event.detail.value) {
this.menuElement.opened = false;
this.menuOpened = false;
}
Expand Down Expand Up @@ -225,8 +226,7 @@ export class Card extends BasicElement {
*/
protected firstUpdated (changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties);

this.addEventListener('item-trigger', this.closeMenu); // Here to cover nested menus
this.addEventListener('item-trigger', (event) => this.closeMenu(event as ItemTriggerEvent)); // Here to cover nested menus
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/elements/src/overlay-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ export class OverlayMenu extends Overlay {
.label=${label}
.subLabel=${subLabel}
.icon=${icon}
.value=${value}
.value=${ifDefined(value)}
wattachai-lseg marked this conversation as resolved.
Show resolved Hide resolved
.for=${ifDefined(forMenu || undefined)}>
</ef-item>`;
}
Expand Down