From e6a4eadf1ccaa1413a8df4910af171d3a0e83a9d Mon Sep 17 00:00:00 2001 From: konnorrogers Date: Wed, 8 May 2024 14:24:11 -0400 Subject: [PATCH] fixing validation --- docs/_layouts/component.njk | 18 +-- docs/docs/components/radio-group.md | 4 +- src/components/button/button.ts | 135 ++++++++------------ src/components/color-picker/color-picker.ts | 11 -- src/components/input/input.test.ts | 5 +- src/components/input/input.ts | 14 +- src/components/radio-button/radio-button.ts | 11 +- src/components/radio-group/radio-group.ts | 4 +- src/components/range/range.ts | 10 -- src/components/textarea/textarea.ts | 9 -- src/internal/validators/mirror-validator.ts | 2 +- src/internal/webawesome-element.ts | 20 ++- 12 files changed, 96 insertions(+), 147 deletions(-) diff --git a/docs/_layouts/component.njk b/docs/_layouts/component.njk index 045f4515e..423921960 100644 --- a/docs/_layouts/component.njk +++ b/docs/_layouts/component.njk @@ -31,7 +31,7 @@ {# Component API #} {% block afterContent %} {# Slots #} - {% if component.slots.length %} + {% if component.slots?.length %}

Slots

@@ -61,7 +61,7 @@ {% endif %} {# Properties #} - {% if component.properties.length %} + {% if component.properties?.length %}

Properties

@@ -113,7 +113,7 @@ {% endif %} {# Methods #} - {% if component.methods.length %} + {% if component.methods?.length %}

Methods

@@ -130,7 +130,7 @@
{{ method.name }}() {{ method.description | inlineMarkdown | safe }} - {% if method.parameters.length %} + {% if method.parameters?.length %} {% for param in method.parameters %} {{ param.name }}: {{ param.type.text | trimPipes }}{% if not loop.last %},{% endif %} @@ -146,7 +146,7 @@ {% endif %} {# States #} - {% if component.states.length %} + {% if component.states?.length %}

States

@@ -171,7 +171,7 @@ {% endif %} {# Events #} - {% if component.events.length %} + {% if component.events?.length %}

Events

@@ -195,7 +195,7 @@ {% endif %} {# Custom Properties #} - {% if component.cssProperties.length %} + {% if component.cssProperties?.length %}

CSS custom properties

@@ -225,7 +225,7 @@ {% endif %} {# CSS Parts #} - {% if component.cssParts.length %} + {% if component.cssParts?.length %}

CSS parts

@@ -251,7 +251,7 @@ {% endif %} {# Dependencies #} - {% if component.dependencies.length %} + {% if component.dependencies?.length %}

Dependencies

This component automatically imports the following elements. Subdependencies, if any exist, will also be included in this list. diff --git a/docs/docs/components/radio-group.md b/docs/docs/components/radio-group.md index b1d85799f..86a66c7bb 100644 --- a/docs/docs/components/radio-group.md +++ b/docs/docs/components/radio-group.md @@ -244,7 +244,7 @@ Use the `setCustomValidity()` method to set a custom validation message. This wi const errorMessage = 'You must choose the last option'; // Set initial validity as soon as the element is defined - customElements.whenDefined('wa-radio').then(() => { + customElements.whenDefined('wa-radio-group').then(() => { radioGroup.setCustomValidity(errorMessage); }); @@ -301,4 +301,4 @@ const App = () => { ); }; ``` -{% endraw %} +{% endraw %} \ No newline at end of file diff --git a/src/components/button/button.ts b/src/components/button/button.ts index 4c671520b..b0dd63a15 100644 --- a/src/components/button/button.ts +++ b/src/components/button/button.ts @@ -1,18 +1,17 @@ import '../icon/icon.js'; import '../spinner/spinner.js'; import { classMap } from 'lit/directives/class-map.js'; -import { customElement, property, query, state } from 'lit/decorators.js'; -import { FormControlController, validValidityState } from '../../internal/form.js'; import { HasSlotController } from '../../internal/slot.js'; import { html, literal } from 'lit/static-html.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { LocalizeController } from '../../utilities/localize.js'; +import { MirrorValidator } from '../../internal/validators/mirror-validator.js'; +import { customElement, property, query, state } from 'lit/decorators.js'; import { watch } from '../../internal/watch.js'; +import { WebAwesomeFormAssociated } from '../../internal/webawesome-element.js'; import componentStyles from '../../styles/component.styles.js'; import styles from './button.styles.js'; -import WebAwesomeElement from '../../internal/webawesome-element.js'; import type { CSSResultGroup } from 'lit'; -import type { WebAwesomeFormControl } from '../../internal/webawesome-element.js'; /** * @summary Buttons represent actions that are available to the user. @@ -53,13 +52,17 @@ import type { WebAwesomeFormControl } from '../../internal/webawesome-element.js * @cssproperty --label-color-active - The color of the button's label when active. * @cssproperty --label-color-hover - The color of the button's label on hover. */ -@customElement('wa-button') -export default class WaButton extends WebAwesomeElement implements WebAwesomeFormControl { +@customElement("wa-button") +export default class WaButton extends WebAwesomeFormAssociated { static styles: CSSResultGroup = [componentStyles, styles]; - private readonly formControlController = new FormControlController(this, { - assumeInteractionOn: ['click'] - }); + static get validators () { + return [ + MirrorValidator() + ] + } + + assumeInteractionOn = ["click"] private readonly hasSlotController = new HasSlotController(this, '[default]', 'prefix', 'suffix'); private readonly localize = new LocalizeController(this); @@ -79,7 +82,7 @@ export default class WaButton extends WebAwesomeElement implements WebAwesomeFor @property({ type: Boolean, reflect: true }) caret = false; /** Disables the button. */ - @property({ type: Boolean, reflect: true }) disabled = false; + @property({ type: Boolean }) disabled = false; /** Draws the button in a loading state. */ @property({ type: Boolean, reflect: true }) loading = false; @@ -106,7 +109,7 @@ export default class WaButton extends WebAwesomeElement implements WebAwesomeFor * The value of the button, submitted as a pair with the button's name as part of the form data, but only when this * button is the submitter. This attribute is ignored when `href` is present. */ - @property() value = ''; + @property({ reflect: true }) value = ''; /** When set, the underlying button will be rendered as an `` with this `href` instead of a `