Skip to content

Commit

Permalink
fix(core/form-controls): readonly states (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalosard authored Apr 14, 2023
1 parent a595268 commit 696366d
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/core/scss/components/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
box-shadow: none !important;
outline: none !important;
border-color: var(--theme-input--border-color);
cursor: default !important;

&::placeholder {
color: transparent;
}
}

.form-control:disabled,
Expand Down
18 changes: 13 additions & 5 deletions packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,18 @@ export class Select {
this.dropdownShow = false;
}

private placeholderValue() {
if (this.editable) {
return this.i18nPlaceholderEditable;
}

if (this.readonly) {
return '';
}

return this.i18nPlaceholder;
}

render() {
return (
<Host>
Expand Down Expand Up @@ -396,11 +408,7 @@ export class Select {
class={{
'allow-clear': this.allowClear && !!this.value?.length,
}}
placeholder={
this.editable
? this.i18nPlaceholderEditable
: this.i18nPlaceholder
}
placeholder={this.placeholderValue()}
value={this.inputValue}
ref={(ref) => (this.inputRef = ref)}
onInput={() => this.filterItemsWithTypeahead()}
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/tests/input/input.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ regressionTest.describe('input', () => {
await page.waitForTimeout(1000);
expect(await page.screenshot()).toMatchSnapshot();
});

regressionTest('readonly', async ({ page }) => {
await page.goto('input/readonly');
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.
22 changes: 22 additions & 0 deletions packages/core/src/tests/input/readonly/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
SPDX-FileCopyrightText: 2023 Siemens AG
SPDX-License-Identifier: MIT
-->

<html>

<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>
<div class="m-2">
<input class="form-control" defaultValue="" placeholder="Enter text here" type="text" readonly />
</div>
<script src="http://127.0.0.1:8080/scripts/e2e/load-e2e-runtime.js"></script>
</body>

</html>
25 changes: 25 additions & 0 deletions packages/core/src/tests/select/readonly/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
SPDX-FileCopyrightText: 2023 Siemens AG
SPDX-License-Identifier: MIT
-->

<html>

<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 style="padding: 2rem">
<ix-select readonly>
<ix-select-item label="Item 1" value="1"></ix-select-item>
<ix-select-item label="Item 2" value="2"></ix-select-item>
<ix-select-item label="Item 3" value="3"></ix-select-item>
<ix-select-item label="Item 4" value="4"></ix-select-item>
</ix-select>
<script src="http://127.0.0.1:8080/scripts/e2e/load-e2e-runtime.js"></script>
</body>

</html>
5 changes: 5 additions & 0 deletions packages/core/src/tests/select/select.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ regressionTest.describe('select', () => {
await page.waitForSelector('.dropdown-menu.show');
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot();
});

regressionTest('readonly', async ({ page }) => {
await page.goto('select/readonly');
expect(await page.screenshot({ fullPage: true })).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.
22 changes: 22 additions & 0 deletions packages/core/src/tests/textarea/basic/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
SPDX-FileCopyrightText: 2023 Siemens AG
SPDX-License-Identifier: MIT
-->

<html>

<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>
<div class="m-2">
<textarea class="form-control" placeholder="Enter text here"></textarea>
</div>
<script src="http://127.0.0.1:8080/scripts/e2e/load-e2e-runtime.js"></script>
</body>

</html>
22 changes: 22 additions & 0 deletions packages/core/src/tests/textarea/readonly/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
SPDX-FileCopyrightText: 2023 Siemens AG
SPDX-License-Identifier: MIT
-->

<html>

<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>
<div class="m-2">
<textarea class="form-control" placeholder="Enter text here" readonly></textarea>
</div>
<script src="http://127.0.0.1:8080/scripts/e2e/load-e2e-runtime.js"></script>
</body>

</html>
23 changes: 23 additions & 0 deletions packages/core/src/tests/textarea/textarea.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-FileCopyrightText: 2023 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 { expect } from '@playwright/test';
import { regressionTest } from '@utils/test';

regressionTest.describe('textarea', () => {
regressionTest('basic', async ({ page }) => {
await page.goto('textarea/basic');
expect(await page.screenshot()).toMatchSnapshot();
});

regressionTest('readonly', async ({ page }) => {
await page.goto('textarea/readonly');
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.
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.

0 comments on commit 696366d

Please sign in to comment.