diff --git a/src/components/cc-input-text/cc-input-text.js b/src/components/cc-input-text/cc-input-text.js index 35313120a..089a42ca2 100644 --- a/src/components/cc-input-text/cc-input-text.js +++ b/src/components/cc-input-text/cc-input-text.js @@ -1,13 +1,16 @@ -import { css, html, LitElement } from 'lit'; +import { css, html } from 'lit'; import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; +import { createRef, ref } from 'lit/directives/ref.js'; import { + iconRemixCheckLine as iconCheck, iconRemixClipboardLine as iconClipboard, - iconRemixEyeOffLine as iconEyeClosed, iconRemixEyeLine as iconEyeOpen, - iconRemixCheckLine as iconCheck, + iconRemixEyeOffLine as iconEyeClosed, } from '../../assets/cc-remix.icons.js'; import { dispatchCustomEvent } from '../../lib/events.js'; +import { CcFormControlElement } from '../../lib/form/cc-form-control-element.abstract.js'; +import { combineValidators, EmailValidator, RequiredValidator } from '../../lib/form/validation.js'; import { i18n } from '../../lib/i18n.js'; import { arrayEquals } from '../../lib/utils.js'; import { accessibilityStyles } from '../../styles/accessibility.js'; @@ -16,6 +19,16 @@ import '../cc-icon/cc-icon.js'; const TAG_SEPARATOR = ' '; +/** + * @typedef {import('lit/directives/ref.js').Ref} HTMLInputOrTextareaElementRef + * @typedef {import('lit/directives/ref.js').Ref} HTMLElementRef + * @typedef {import('../../lib/events.types.js').EventWithTarget} HTMLInputOrTextareaEvent + * @typedef {import('../../lib/events.types.js').GenericEventWithTarget} HTMLInputOrTextareaKeyboardEvent + * @typedef {import('../../lib/form/validation.types.js').Validator} Validator + * @typedef {import('../../lib/form/validation.types.js').ErrorMessageMap} ErrorMessageMap + * @typedef {import('../../lib/form/form.types.js').FormControlData} FormControlData + */ + /** * An enhanced text input with support for multiline, copy-to-clipboard, show/hide secret and highlighted tags. * @@ -25,7 +38,7 @@ const TAG_SEPARATOR = ' '; * * When you use it with `readonly` \+ `clipboard` \+ NOT `multi`, the width of the input auto adapts to the length of the content. * * The `secret` feature only works for simple line mode (when `multi` is false). * * The `tags` feature enables a space-separated-value input wrapped on several lines where line breaks are not allowed. Don't use it with `multi` or `secret`. - * * When an error slot is used, the input is decorated with a red border and a redish focus ring. You have to be aware that it uses the [`slotchange`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/slotchange_event) event which doesn't fire if the children of a slotted node change. + * * When an `errorMessage` is set, the input is decorated with a red border and a redish focus ring. * * @cssdisplay inline-block / block (with `[multi]`) * @@ -39,34 +52,36 @@ const TAG_SEPARATOR = ' '; * @cssprop {FontSize} --cc-input-label-font-size - The font-size for the input's label (defaults: `inherit`). * @cssprop {FontWeight} --cc-input-label-font-weight - The font-weight for the input's label (defaults: `normal`). * - * @slot error - The error message to be displayed below the `` element or below the help text. Please use a `

` tag. * @slot help - The help message to be displayed right below the `` element. Please use a `

` tag. */ -export class CcInputText extends LitElement { +export class CcInputText extends CcFormControlElement { static get properties () { return { + ...super.properties, clipboard: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true }, label: { type: String }, hiddenLabel: { type: Boolean, attribute: 'hidden-label' }, inline: { type: Boolean, reflect: true }, multi: { type: Boolean, reflect: true }, - name: { type: String, reflect: true }, placeholder: { type: String }, readonly: { type: Boolean, reflect: true }, required: { type: Boolean }, + resetValue: { type: String, attribute: 'reset-value' }, secret: { type: Boolean, reflect: true }, skeleton: { type: Boolean, reflect: true }, tags: { type: Array }, + type: { type: String, reflect: true }, value: { type: String }, _copyOk: { type: Boolean, state: true }, _showSecret: { type: Boolean, state: true }, _tagsEnabled: { type: Boolean, state: true }, - _hasError: { type: Boolean, state: true }, }; } + static reactiveValidationProperties = ['required', 'type']; + constructor () { super(); @@ -90,9 +105,6 @@ export class CcInputText extends LitElement { /** @type {boolean} Enables multiline support (with a ` ` : ''} @@ -283,15 +391,15 @@ export class CcInputText extends LitElement { ` : ''} @@ -300,7 +408,7 @@ export class CcInputText extends LitElement { ${secret ? html`