Skip to content

Commit

Permalink
refactor: fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
Davut Enes Yıldırım committed Jan 9, 2025
1 parent daa7830 commit 3f37995
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
15 changes: 10 additions & 5 deletions playground/template.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<html lang="tr">
<head>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Baklava Playground</title>
<link href="./dist/themes/default.css" rel="stylesheet" />
<script src="./dist/localization.js" type="module"></script>
<script src="./dist/baklava.js" type="module"></script>
<script>
// Live reload
Expand All @@ -27,11 +28,15 @@
<body>
<h1>Baklava Playground</h1>

<p>
Copy this file as playground/index.html and try your work here by running
<code>npm run serve</code>.
</p>
<bl-input id="sa" />

<bl-button>Baklava is ready</bl-button>
</body>

<script>
const sa = document.querySelector("#sa");
sa.updateComplete.then(() => {
sa.forceCustomError();
})
</script>
</html>
9 changes: 7 additions & 2 deletions src/components/input/bl-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { customElement, property, query, state } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { live } from "lit/directives/live.js";
import { localized, msg } from "@lit/localize";
import { FormControlMixin } from "@open-wc/form-control";
import { submit } from "@open-wc/form-helpers";
import "element-internals-polyfill";
Expand Down Expand Up @@ -45,6 +46,7 @@ export type InputSize = "small" | "medium" | "large";
* @cssproperty [--bl-input-padding-end] Sets the padding end
*/
@customElement("bl-input")
@localized()
export default class BlInput extends FormControlMixin(LitElement) {
static get styles(): CSSResultGroup {
return [style];
Expand Down Expand Up @@ -200,7 +202,7 @@ export default class BlInput extends FormControlMixin(LitElement) {
}

@property({ reflect: true, type: String })
error: string = "";
error: string;

private _customInvalidText: string;

Expand Down Expand Up @@ -282,7 +284,10 @@ export default class BlInput extends FormControlMixin(LitElement) {
*/
async forceCustomError() {
await this.updateComplete;
this.setCustomValidity(this.customInvalidText || "An error occurred");
this.setCustomValidity(
this.customInvalidText ||
msg("An error occurred", { desc: "bl-input: default custom error message" })
);
this.setValue(this.value);
this.reportValidity();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/textarea/bl-textarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class BlTextarea extends FormControlMixin(LitElement) {
validationTarget: HTMLTextAreaElement;

@property({ reflect: true, type: String })
error: string = "";
error: string;

/**
* Name of textarea
Expand Down
1 change: 1 addition & 0 deletions src/generated/locales/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

export const templates = {
's144508ac0e146c46': `Hiçbir Sonuç Bulunamadı`,
's3f9c368cd44f682b': `Bir hata oluştu`,
's5d929ff1619ac0c9': `Arama`,
's716a6024e3fe999c': `Göster`,
's76ddb3a843ed8e06': `Aramayı Temizle`,
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/form-control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MyInvalidInput extends LitElement {
validationTarget: HTMLInputElement;

@property({ reflect: true, type: String })
error: string = "";
error: string;

render() {
return html`<input required />`;
Expand All @@ -27,7 +27,7 @@ class MyCustomErrorInput extends LitElement {
validationTarget: HTMLInputElement;

@property({ reflect: true, type: String })
error: string = "";
error: string;

render() {
return html`<input />`;
Expand Down
5 changes: 5 additions & 0 deletions translations/tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<target>Tümünü Seç</target>
<note from="lit-localize">bl-select: select all text</note>
</trans-unit>
<trans-unit id="s3f9c368cd44f682b">
<source>An error occurred</source>
<target>Bir hata oluştu</target>
<note from="lit-localize">bl-input: default custom error message</note>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 3f37995

Please sign in to comment.