Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions src/__test__/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
4 changes: 2 additions & 2 deletions src/components/chat-item/chat-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
` ],
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down Expand Up @@ -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() ?? '';
Expand Down