@fluid-topics/ft-text-field 1.3.53 → 1.3.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,7 @@ export declare class FtTextField extends FtTextField_base implements FtTextField
32
32
  autocomplete?: string;
33
33
  suggestionsProvider?: (query: string) => FtTextFieldSuggestionDefinition[] | Promise<FtTextFieldSuggestionDefinition[]>;
34
34
  focused: boolean;
35
+ inputValid: boolean;
35
36
  hidePassword: boolean;
36
37
  hideSuggestions: boolean;
37
38
  visibleSuggestions: FtTextFieldSuggestion[];
@@ -10,12 +10,13 @@ import { repeat } from "lit/directives/repeat.js";
10
10
  import { classMap } from "lit/directives/class-map.js";
11
11
  import { ifDefined } from "lit/directives/if-defined.js";
12
12
  import { computeOffsetAutoPosition, FtLitElement, noTextInputDefaultClearButton, toFtFormComponent } from "@fluid-topics/ft-wc-utils";
13
- import { FtTypography, FtTypographyBody1 } from "@fluid-topics/ft-typography";
13
+ import { FtTypography, FtTypographyBody1, FtTypographyVariants } from "@fluid-topics/ft-typography";
14
14
  import { FtInputLabel } from "@fluid-topics/ft-input-label";
15
15
  import { FtRipple } from "@fluid-topics/ft-ripple";
16
16
  import { FtIcon, FtIcons } from "@fluid-topics/ft-icon";
17
17
  import { styles } from "./ft-text-field.styles";
18
18
  import { FtTextFieldSuggestion } from "./ft-text-field-suggestion";
19
+ import { FtTextFieldChangeEvent, FtTextFieldInvalidEvent, FtTextFieldLiveChangeEvent } from "./models";
19
20
  class FtTextField extends toFtFormComponent(FtLitElement) {
20
21
  constructor() {
21
22
  super(...arguments);
@@ -31,6 +32,7 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
31
32
  this.filterSuggestions = false;
32
33
  this.password = false;
33
34
  this.focused = false;
35
+ this.inputValid = true;
34
36
  this.hidePassword = true;
35
37
  this.hideSuggestions = false;
36
38
  this.visibleSuggestions = [];
@@ -65,6 +67,7 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
65
67
  (_a = this.input) === null || _a === void 0 ? void 0 : _a.blur();
66
68
  }
67
69
  render() {
70
+ var _a;
68
71
  const classes = {
69
72
  "ft-text-field": true,
70
73
  "ft-text-field--filled": !this.outlined,
@@ -72,7 +75,7 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
72
75
  "ft-text-field--disabled": this.disabled,
73
76
  "ft-text-field--has-value": !!this.value,
74
77
  "ft-text-field--with-label": !!this.label,
75
- "ft-text-field--in-error": this.error,
78
+ "ft-text-field--in-error": !this.inputValid || this.error,
76
79
  "ft-text-field--fixed": this.fixedMenuPosition,
77
80
  "ft-text-field--with-prefix": !!this.prefix,
78
81
  "ft-text-field--hide-suggestions": !this.suggestionsShouldBeDisplayed(),
@@ -83,6 +86,7 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
83
86
  const suggestionsAreProvidedAndQueryNotInPossiblesValues = this.suggestionsProvider && this.value && this.value != "" && !this.providedSuggestions.map((p) => p.label).includes(this.value);
84
87
  const suggestionsFromSlotAndQueryNotEmpty = !this.suggestionsProvider && this.filterSuggestions && this.value && this.value != "";
85
88
  const shouldDisplayQueryAsNewSuggestion = suggestionsFromSlotAndQueryNotEmpty || suggestionsAreProvidedAndQueryNotInPossiblesValues;
89
+ const helper = this.inputValid ? this.helper : (_a = this.input) === null || _a === void 0 ? void 0 : _a.validationMessage;
86
90
  return html `
87
91
  <div class="${classMap(classes)}">
88
92
  <div class="ft-text-field--main-panel"
@@ -92,7 +96,7 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
92
96
  ?disabled=${this.disabled}
93
97
  ?outlined=${this.outlined}
94
98
  ?raised=${this.focused || this.value != ""}
95
- ?error=${this.error}></ft-input-label>
99
+ ?error=${!this.inputValid || this.error}></ft-input-label>
96
100
  <div class="ft-text-field--input-panel">
97
101
  ${this.outlined ? nothing : html `
98
102
  <ft-ripple ?disabled=${this.disabled} activated></ft-ripple>
@@ -113,8 +117,9 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
113
117
  .value=${this.value}
114
118
  @click=${this.handleClick}
115
119
  @keyup=${this.handleInput}
116
- @focus=${this.onFocus}/>
117
- ${(this.renderIcon())}
120
+ @focus=${this.onFocus}
121
+ />
122
+ ${this.renderIcon()}
118
123
  </div>
119
124
  <div class="ft-text-field--suggestions"
120
125
  @suggestion-selected=${this.onSuggestionSelected}>
@@ -128,9 +133,9 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
128
133
  : nothing}
129
134
  </div>
130
135
  </div>
131
- ${this.helper ? html `
132
- <ft-typography class="ft-text-field--helper-text" variant="caption">
133
- ${this.helper}
136
+ ${helper ? html `
137
+ <ft-typography class="ft-text-field--helper-text" variant="${FtTypographyVariants.caption}">
138
+ ${helper}
134
139
  </ft-typography>
135
140
  ` : nothing}
136
141
  </div>
@@ -153,7 +158,8 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
153
158
  `
154
159
  : nothing}
155
160
  ${suggestion.label}
156
- </ft-text-field-suggestion>`)}
161
+ </ft-text-field-suggestion>
162
+ `)}
157
163
  `;
158
164
  }
159
165
  else {
@@ -263,13 +269,21 @@ class FtTextField extends toFtFormComponent(FtLitElement) {
263
269
  this.clearWatchAutofill();
264
270
  }
265
271
  setValue(newValue, fireChangeEvent = false) {
272
+ var _a, _b;
266
273
  if (this.value !== newValue) {
274
+ this.inputValid = true;
267
275
  this.setInternalValue(newValue);
268
- this.dispatchEvent(new CustomEvent("live-change", { detail: newValue }));
276
+ this.dispatchEvent(new FtTextFieldLiveChangeEvent(newValue));
269
277
  }
270
278
  if (fireChangeEvent && this.dispatchedValue !== newValue) {
271
- this.dispatchedValue = newValue;
272
- this.dispatchEvent(new CustomEvent("change", { detail: newValue }));
279
+ this.inputValid = (_b = (_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity()) !== null && _b !== void 0 ? _b : true;
280
+ if (this.inputValid) {
281
+ this.dispatchedValue = newValue;
282
+ this.dispatchEvent(new FtTextFieldChangeEvent(newValue));
283
+ }
284
+ else {
285
+ this.dispatchEvent(new FtTextFieldInvalidEvent(this.input.validationMessage));
286
+ }
273
287
  }
274
288
  }
275
289
  handleInput(event) {
@@ -415,6 +429,9 @@ __decorate([
415
429
  __decorate([
416
430
  state()
417
431
  ], FtTextField.prototype, "focused", void 0);
432
+ __decorate([
433
+ state()
434
+ ], FtTextField.prototype, "inputValid", void 0);
418
435
  __decorate([
419
436
  state()
420
437
  ], FtTextField.prototype, "hidePassword", void 0);