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(core/drawer|inputgroup): fixed drawer display issue #1561

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
5 changes: 5 additions & 0 deletions .changeset/proud-waves-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siemens/ix': patch
---

fix(core/input-group): update slot references
matthiashader marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10213,11 +10213,17 @@
"overview": "",
"usage": {},
"docs": "",
"docsTags": [],
"docsTags": [
{
"name": "deprecated",
"text": "since 2.6.1. Will be removed with 3.0.0.\nUse the 'ix-input' component instead"
}
],
"encapsulation": "shadow",
"dependents": [],
"dependencies": [],
"dependencyGraph": {},
"deprecation": "since 2.6.1. Will be removed with 3.0.0.\nUse the 'ix-input' component instead",
"props": [],
"methods": [],
"events": [],
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,10 @@ export namespace Components {
*/
"warningText"?: string;
}
/**
* @deprecated since 2.6.1. Will be removed with 3.0.0.
* Use the 'ix-input' component instead
*/
interface IxInputGroup {
}
/**
Expand Down Expand Up @@ -4131,6 +4135,10 @@ declare global {
prototype: HTMLIxInputElement;
new (): HTMLIxInputElement;
};
/**
* @deprecated since 2.6.1. Will be removed with 3.0.0.
* Use the 'ix-input' component instead
*/
interface HTMLIxInputGroupElement extends Components.IxInputGroup, HTMLStencilElement {
}
var HTMLIxInputGroupElement: {
Expand Down Expand Up @@ -6744,6 +6752,10 @@ declare namespace LocalJSX {
*/
"warningText"?: string;
}
/**
* @deprecated since 2.6.1. Will be removed with 3.0.0.
* Use the 'ix-input' component instead
*/
interface IxInputGroup {
}
/**
Expand Down Expand Up @@ -8693,6 +8705,10 @@ declare module "@stencil/core" {
* @form-ready 2.6.0
*/
"ix-input": LocalJSX.IxInput & JSXBase.HTMLAttributes<HTMLIxInputElement>;
/**
* @deprecated since 2.6.1. Will be removed with 3.0.0.
* Use the 'ix-input' component instead
*/
"ix-input-group": LocalJSX.IxInputGroup & JSXBase.HTMLAttributes<HTMLIxInputGroupElement>;
/**
* @since 1.6.0
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/components/drawer/drawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
visibility: hidden;

display: flex;
position: absolute;
position: fixed;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a breaking change. Can we do without that?

flex-flow: column nowrap;
justify-content: flex-start;
align-items: center;
transform: translateX(16rem);
opacity: 0;

max-height: 100vh;
min-height: $large-space;
background-color: var(--theme-color-1);
border-radius: $default-border-radius;

transition: all var(--theme-medium-time) ease-out;
transition: transform var(--theme-medium-time) ease-out;

.toggle {
z-index: 100;
Expand All @@ -55,7 +57,6 @@
.content {
position: relative;
flex: 1;
flex-grow: 1;
order: 2;
height: 100%;
width: 100%;
Expand All @@ -66,3 +67,7 @@
:host(.toggle) {
visibility: visible;
}

:host(.display-none) {
display: none;
}
9 changes: 5 additions & 4 deletions packages/core/src/components/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class Drawer {
private divElement?: HTMLElement;

@Watch('show')
onShowChanged(newValue: boolean) {
onShowChanged(newValue: boolean, oldValue?: boolean) {
if (newValue === !!oldValue) return;
this.show = newValue !== undefined ? newValue : !this.show;
this.toggleDrawer(this.show);
}
Expand Down Expand Up @@ -129,7 +130,7 @@ export class Drawer {
opacity: [1, 0],
easing: 'easeInSine',
complete: () => {
el.classList.add('d-none');
el.classList.add('display-none');
},
});
}
Expand All @@ -144,7 +145,7 @@ export class Drawer {
opacity: [0, 1],
easing: 'easeOutSine',
begin: () => {
el.classList.remove('d-none');
el.classList.remove('display-none');
},
});
}
Expand All @@ -160,7 +161,7 @@ export class Drawer {
class={{
'drawer-container': true,
toggle: this.show,
'd-none': true,
'display-none': true,
}}
style={{
width: this.width === 'auto' ? this.width : `${this.width}rem`,
Expand Down
75 changes: 38 additions & 37 deletions packages/core/src/components/input-group/input-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import { Component, Element, h, Host, State } from '@stencil/core';
import { getSlottedElements } from '../utils/shadow-dom';

/**
* @deprecated since 2.6.1. Will be removed with 3.0.0.
* Use the 'ix-input' component instead
*/
@Component({
tag: 'ix-input-group',
styleUrl: 'input-group.scss',
Expand All @@ -23,11 +27,14 @@ export class InputGroup {
@State() inputPaddingLeft = 0;
@State() inputPaddingRight = 0;

startSlotRef?: HTMLElement;
endSlotRef?: HTMLElement;

private get inputElement() {
return this.hostElement.querySelector('input') as HTMLInputElement;
}

private observer: MutationObserver;
private observer?: MutationObserver;

componentWillLoad() {
const { valid } = this.inputElement.validity;
Expand Down Expand Up @@ -100,50 +107,38 @@ export class InputGroup {
}

private startSlotChanged() {
const slot = this.hostElement.shadowRoot.querySelector(
'slot[name="input-start"]'
);

setTimeout(() => {
const startPadding = this.getChildrenWidth(slot);
const startPadding = this.getChildrenWidth(this.startSlotRef);

if (startPadding !== 0) {
this.inputPaddingLeft = 11 + startPadding;
} else {
this.inputPaddingLeft = 0;
}
if (startPadding !== 0) {
this.inputPaddingLeft = 11 + startPadding;
} else {
this.inputPaddingLeft = 0;
}

if (!this.inputElement) {
return;
}
if (!this.inputElement) {
return;
}

const isInputInvalid =
!this.inputElement.validity.valid ||
this.inputElement.classList.contains('is-invalid');
const isInputInvalid =
!this.inputElement.validity.valid ||
this.inputElement.classList.contains('is-invalid');

const formWasValidated =
this.inputElement.form?.classList.contains('was-validated') ||
this.inputElement.form?.noValidate === false;
const formWasValidated =
this.inputElement.form?.classList.contains('was-validated') ||
this.inputElement.form?.noValidate === false;

if (formWasValidated && isInputInvalid) {
const left = this.inputPaddingLeft !== 0 ? this.inputPaddingLeft : 7;
this.inputElement.style.backgroundPosition = `left ${left}px center`;
this.inputPaddingLeft += 26;
}
});
if (formWasValidated && isInputInvalid) {
const left = this.inputPaddingLeft !== 0 ? this.inputPaddingLeft : 7;
this.inputElement.style.backgroundPosition = `left ${left}px center`;
this.inputPaddingLeft += 26;
}
}

private endSlotChanged() {
const slot = this.hostElement.shadowRoot.querySelector(
'slot[name="input-end"]'
);

setTimeout(() => {
this.inputPaddingRight = 15 + this.getChildrenWidth(slot);
});
this.inputPaddingRight = 15 + this.getChildrenWidth(this.endSlotRef);
}

private getChildrenWidth(slotElement: Element) {
private getChildrenWidth(slotElement: Element | undefined) {
if (!slotElement) {
return 0;
}
Expand All @@ -166,11 +161,17 @@ export class InputGroup {
return (
<Host class={{ disabled: this.disabled }}>
<div class="group group-start">
<slot name="input-start"></slot>
<slot
ref={(el) => (this.startSlotRef = el as HTMLElement)}
name="input-start"
></slot>
</div>
<slot></slot>
<div class="group group-end">
<slot name="input-end"></slot>
<slot
ref={(el) => (this.endSlotRef = el as HTMLElement)}
name="input-end"
></slot>
</div>
</Host>
);
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/tests/drawer/drawer.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ regressionTest.describe('drawer', () => {
await page.waitForTimeout(2000);
expect(await page.screenshot()).toMatchSnapshot();
});

regressionTest('input-group', async ({ page }) => {
await page.goto('drawer/input-group');
await page.locator('ix-button').click();
await page.waitForTimeout(2000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use waitForSelector instead

expect(await page.screenshot()).toMatchSnapshot();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions packages/core/src/tests/drawer/input-group/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
SPDX-FileCopyrightText: 2024 Siemens AG

SPDX-License-Identifier: MIT
-->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0"
/>
<title>Stencil Component Starter</title>
</head>
<body>
<ix-drawer>
<ix-input-group>
<ix-icon
slot="input-start"
name="success"
size="16">
</ix-icon>
<input />
</ix-input-group>
</ix-drawer>
<ix-button>Click</ix-button>
<script>
const button = document.querySelector('ix-button');
button.addEventListener('click', () => {
document.querySelector('ix-drawer').toggleDrawer(true);
});
</script>
<script src="http://127.0.0.1:8080/scripts/e2e/load-e2e-runtime.js"></script>
</body>
</html>
56 changes: 56 additions & 0 deletions packages/storybook-docs/src/stories/drawer.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* SPDX-FileCopyrightText: 2024 Siemens AG
*
* SPDX-License-Identifier: MIT
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { Components } from '@siemens/ix/components';
import type { ArgTypes, Meta, StoryObj } from '@storybook/web-components';
import { html } from 'lit';
import { makeArgTypes } from './utils/generic-render';

type Element = Components.IxDrawer;

const meta = {
title: 'Example/Drawer',
tags: [],
render: (args) => {
return html` <ix-drawer
closeOnClickOutside=${args.closeOnClickOutside}
?fullHeight=${true}
show=${args.show}
onDrawerClose=${true}
>
<div>
<ix-input-group>
<ix-icon
slot="input-start"
name="success"
color="color-success"
size="16"
/>
<input slot="input-end" />
<span> dasda </span>
</ix-input-group>
</div>
</ix-drawer>`;
},
argTypes: makeArgTypes<Partial<ArgTypes<Element>>>('ix-drawer'),
parameters: {
design: {
type: 'figma',
url: 'https://www.figma.com/design/r2nqdNNXXZtPmWuVjIlM1Q/iX-Components---Brand-Dark?node-id=8033-151366&m=dev',
},
},
} satisfies Meta<Element>;

export default meta;
type Story = StoryObj<Element>;

export const Default: Story = {
args: {
closeOnClickOutside: true,
},
};
Loading