diff --git a/src/__test__/main.spec.ts b/src/__test__/main.spec.ts index f7a8b04f6..8a3d64751 100644 --- a/src/__test__/main.spec.ts +++ b/src/__test__/main.spec.ts @@ -96,4 +96,23 @@ describe('mynah-ui', () => { expect(true).toBe(false); } }); + + it('sets initial selected-tab attribute on tab contents wrapper', () => { + new MynahUI({ + config: { + maxTabs: 1, + }, + tabs: { + [testTabId]: { + isSelected: true, + store: { + loadingChat: false, + } + } + } + }); + + const tabContentsWrapper = document.body.querySelector('.mynah-ui-tab-contents-wrapper'); + expect(tabContentsWrapper?.getAttribute('selected-tab')).toBe(testTabId); + }); }); diff --git a/src/components/chat-item/chat-wrapper.ts b/src/components/chat-item/chat-wrapper.ts index ebcc1d4ee..06583faac 100644 --- a/src/components/chat-item/chat-wrapper.ts +++ b/src/components/chat-item/chat-wrapper.ts @@ -288,13 +288,13 @@ export class ChatWrapper { { type: 'style', children: [ ` - .mynah-nav-tabs-wrapper[selected-tab="${this.props.tabId}"] ~ .mynah-ui-tab-contents-wrapper > .mynah-chat-wrapper[mynah-tab-id="${this.props.tabId}"]{ + .mynah-ui-tab-contents-wrapper[selected-tab="${this.props.tabId}"] > .mynah-chat-wrapper[mynah-tab-id="${this.props.tabId}"]{ visibility: visible; position: relative; left: initial; opacity: 1; } - .mynah-nav-tabs-wrapper[selected-tab="${this.props.tabId}"] ~ .mynah-ui-tab-contents-wrapper > .mynah-chat-wrapper:not([mynah-tab-id="${this.props.tabId}"]) * { + .mynah-ui-tab-contents-wrapper[selected-tab="${this.props.tabId}"] > .mynah-chat-wrapper:not([mynah-tab-id="${this.props.tabId}"]) * { pointer-events: none !important; } ` ], diff --git a/src/main.ts b/src/main.ts index 64e56233b..a70d2d6a4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -420,6 +420,8 @@ export class MynahUI { this.tabsWrapper.setAttribute('selected-tab', MynahUITabsStore.getInstance().getSelectedTabId()); } + this.tabContentsWrapper.setAttribute('selected-tab', MynahUITabsStore.getInstance().getSelectedTabId()); + this.render = DomBuilder.getInstance().createPortal( MynahPortalNames.WRAPPER, { @@ -482,6 +484,9 @@ export class MynahUI { this.props.onTabRemove(tabId, this.getUserEventId()); } }); + MynahUITabsStore.getInstance().addListener('selectedTabChange', (selectedTabId: string) => { + this.tabContentsWrapper.setAttribute('selected-tab', selectedTabId); + }); this.addGlobalListeners(); const tabId = MynahUITabsStore.getInstance().getSelectedTabId() ?? '';