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: reset hidden state when removing panel from tabsheet #7696

Merged
merged 2 commits into from
Aug 28, 2024
Merged
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
23 changes: 22 additions & 1 deletion packages/tabsheet/src/vaadin-tabsheet-mixin.js
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,28 @@ export const TabSheetMixin = (superClass) =>

// Observe the panels slot for nodes. Set the assigned element nodes as the __panels array.
const panelSlot = this.shadowRoot.querySelector('#panel-slot');
this.__panelsObserver = new SlotObserver(panelSlot, () => {
this.__panelsObserver = new SlotObserver(panelSlot, ({ addedNodes, removedNodes }) => {
if (addedNodes.length) {
addedNodes.forEach((node) => {
// Preserve custom hidden attribute to not override it.
if (node.nodeType === Node.ELEMENT_NODE && node.hidden) {
node.__customHidden = true;
}
});
}
if (removedNodes.length) {
removedNodes.forEach((node) => {
// Clear hidden attribute when removing node from the default slot,
// e.g. when changing its slot to `prefix` or `suffix` dynamically.
if (node.nodeType === Node.ELEMENT_NODE && node.hidden) {
if (node.__customHidden) {
delete node.__customHidden;
} else {
node.hidden = false;
}
}
});
}
this.__panels = Array.from(
panelSlot.assignedNodes({
flatten: true,
Expand Down
24 changes: 24 additions & 0 deletions packages/tabsheet/test/tabsheet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,30 @@ describe('tabsheet', () => {

expect(panel.id).to.equal('custom-id');
});

it('should reset hidden state when removing a panel', async () => {
const div = document.createElement('div');
tabsheet.appendChild(div);
await nextFrame();
expect(div.hidden).to.be.true;

div.setAttribute('slot', 'prefix');
await nextFrame();
expect(div.hidden).to.be.false;
});

it('should not remove explicit hidden state', async () => {
const div = document.createElement('div');
// Prefix component explicitly marked as hidden
div.hidden = true;
tabsheet.appendChild(div);
await nextFrame();

div.setAttribute('slot', 'prefix');
await nextFrame();

expect(div.hidden).to.be.true;
});
});

describe('loading', () => {
Expand Down
Loading