Skip to content

Commit

Permalink
fix: reset hidden state when removing panel from tabsheet (#7696)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Aug 28, 2024
1 parent 6f9c373 commit a1c221f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/tabsheet/src/vaadin-tabsheet-mixin.js
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

0 comments on commit a1c221f

Please sign in to comment.