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

feat(core/pane-layout): provide close/open event and default slot #1563

Merged
merged 11 commits into from
Nov 21, 2024
7 changes: 7 additions & 0 deletions .changeset/seven-coins-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siemens/ix-angular': minor
'@siemens/ix': minor
'@siemens/ix-vue': minor
---

Update expandedChange event to trigger only on user interactions and refine default slot behavior in ix-pane-layout.
matthiashader marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 10 additions & 7 deletions packages/core/src/components/pane-layout/pane-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { matchBreakpoint } from '../utils/breakpoints';
shadow: true,
})
export class Panes {
@Element() hostElement: HTMLIxPaneLayoutElement;
@Element() hostElement!: HTMLIxPaneLayoutElement;

/**
* Choose the layout of the panes.
Expand Down Expand Up @@ -59,7 +59,7 @@ export class Panes {
floating: boolean;
}> = [];

private observer: MutationObserver;
private observer?: MutationObserver;

get currentPanes() {
return this.hostElement.querySelectorAll('ix-pane');
Expand Down Expand Up @@ -179,30 +179,30 @@ export class Panes {

if (isLeft) {
if (leftCount) {
pane.slot = undefined;
pane.slot = '';
return;
}
leftCount++;
} else if (isRight) {
if (rightCount) {
pane.slot = undefined;
pane.slot = '';
return;
}
rightCount++;
} else if (isTop) {
if (topCount) {
pane.slot = undefined;
pane.slot = '';
return;
}
topCount++;
} else if (isBottom) {
if (bottomCount) {
pane.slot = undefined;
pane.slot = '';
return;
}
bottomCount++;
} else {
pane.slot = undefined;
pane.slot = '';
return;
}

Expand Down Expand Up @@ -342,6 +342,7 @@ export class Panes {
onClick={() => this.closeFloatingPanes()}
>
<slot name="content"></slot>
<slot></slot>
</div>
<div
key="bottom"
Expand Down Expand Up @@ -392,6 +393,7 @@ export class Panes {
onClick={() => this.closeFloatingPanes()}
>
<slot name="content"></slot>
<slot></slot>
</div>
<div
key="right"
Expand Down Expand Up @@ -435,6 +437,7 @@ export class Panes {
onClick={() => this.closeFloatingPanes()}
>
<slot name="content"></slot>
<slot></slot>
</div>
<div
key="right"
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/components/pane/pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,15 @@ export class Pane {
});
}

@Watch('expanded')
onExpandedChange() {
this.onSizeChange();

this.expandedChanged.emit({
private dispatchExpandedChangedEvent() {
const event = this.expandedChanged.emit({
slot: this.currentSlot ?? '',
expanded: this.expanded,
expanded: !this.expanded,
});

if (!event.defaultPrevented) {
this.expanded = !this.expanded;
}
}

@Watch('parentHeightPx')
Expand Down Expand Up @@ -536,6 +537,7 @@ export class Pane {
}
}

@Watch('expanded')
@Watch('size')
onSizeChange() {
if (this.expanded) {
Expand Down Expand Up @@ -643,9 +645,7 @@ export class Pane {
: this.minimizeIcon
}
ghost
onClick={() => {
this.expanded = !this.expanded;
}}
onClick={() => this.dispatchExpandedChangedEvent()}
aria-controls={`pane-${this.composition}`}
/>
<span
Expand Down
31 changes: 31 additions & 0 deletions packages/core/src/components/pane/test/panes.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,34 @@ test('expanded', async ({ mount, page }) => {
const title = page.locator('h1');
await expect(title).toBeVisible();
});

test('prevent pane expansion', async ({ mount, page }) => {
await mount(`
<ix-pane
heading="LEFT"
composition="left"
variant="inline"
icon="star"
expanded="false"
>
<h1>Test Heading</h1>
</ix-pane>
`);

const pane = page.locator('ix-pane');

await page.evaluate(() => {
const paneElement = document.querySelector('ix-pane');
paneElement?.addEventListener('expandedChanged', (event: Event) => {
event.preventDefault();
});
});

const iconButton = page.locator('ix-icon-button');
await iconButton.click();

const isExpanded = await pane.evaluate(
(el: HTMLIxPaneElement) => el.expanded
);
expect(isExpanded).toBe(false);
});
Loading