From ea6ac8da8d3e3881f31bb6397f4d551babca8b30 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Tue, 14 Jul 2020 09:22:30 -0400 Subject: [PATCH] Updates --- docs/components/input.md | 5 --- docs/components/select.md | 38 +++++++++++++++++++++ src/components.d.ts | 16 +++++++++ src/components/input/input.tsx | 3 +- src/components/select/select.scss | 32 +++++++++++++++++ src/components/select/select.tsx | 51 +++++++++++++++++----------- src/components/textarea/textarea.tsx | 4 +-- 7 files changed, 120 insertions(+), 29 deletions(-) diff --git a/docs/components/input.md b/docs/components/input.md index 59787fa8b..13649c8d5 100644 --- a/docs/components/input.md +++ b/docs/components/input.md @@ -137,9 +137,4 @@ Show a valid or invalid state by setting the `valid` and `invalid` attributes, r ``` -The easiest way to handle validation in Shoelace is with the `valid` and `invalid` props shown above. This is designed to work well with client-side and server-side validation. - -[HTML form validation](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation#Using_built-in_form_validation) is also possible with limitations. For example, providing validation styles to all the component's internals (e.g. prefix, suffix, labels, and help text) is not a trivial task with this approach. If you only care about styling the underlying _native input_, you can target the component's `input` part with the `:valid` and `:invalid` selector. - - [component-metadata:sl-input] diff --git a/docs/components/select.md b/docs/components/select.md index fc44ed58c..fd9ae1b2b 100644 --- a/docs/components/select.md +++ b/docs/components/select.md @@ -32,6 +32,20 @@ Use the `label` attribute to give the select an accessible label. ``` +### Help Text + +Add descriptive help text to an input with the `help-text` slot. + +```html preview + + Novice + Intermediate + Advanced + +
Please tell us your skill level.
+
+``` + ### Multiple To allow multiple options to be selected, use the `multiple` attribute. @@ -118,4 +132,28 @@ Use the `disabled` prop to disable a select. ``` +### Validation + +Show a valid or invalid state by setting the `valid` and `invalid` attributes, respectively. Help text can be used to provide feedback for validation and will be styled accordingly. + +```html preview + + Option 1 + Option 2 + Option 3 + +
This is a valid selection!
+
+ +
+ + + Option 1 + Option 2 + Option 3 + +
This is not a valid selection!
+
+``` + [component-metadata:sl-select] diff --git a/src/components.d.ts b/src/components.d.ts index a86e3acbe..6515497ce 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -568,6 +568,10 @@ export namespace Components { * Set to true to disable the select control. */ "disabled": boolean; + /** + * Set to true to indicate that the user input is invalid. + */ + "invalid": boolean; /** * The select's label. */ @@ -596,6 +600,10 @@ export namespace Components { * The select's size. */ "size": 'small' | 'medium' | 'large'; + /** + * Set to true to indicate that the user input is valid. + */ + "valid": boolean; /** * The value of the control. This will be a string or an array depending on `multiple`. */ @@ -1682,6 +1690,10 @@ declare namespace LocalJSX { * Set to true to disable the select control. */ "disabled"?: boolean; + /** + * Set to true to indicate that the user input is invalid. + */ + "invalid"?: boolean; /** * The select's label. */ @@ -1722,6 +1734,10 @@ declare namespace LocalJSX { * The select's size. */ "size"?: 'small' | 'medium' | 'large'; + /** + * Set to true to indicate that the user input is valid. + */ + "valid"?: boolean; /** * The value of the control. This will be a string or an array depending on `multiple`. */ diff --git a/src/components/input/input.tsx b/src/components/input/input.tsx index 14e4ad43a..3cce5b932 100644 --- a/src/components/input/input.tsx +++ b/src/components/input/input.tsx @@ -6,7 +6,6 @@ let id = 0; * @since 1.0 * @status stable * - * @slot label - The input's label. Alternatively, you can use the label prop. * @slot prefix - Used to prepend an icon or similar element to the input. * @slot suffix - Used to append an icon or similar element to the input. * @slot clear-icon - An icon to use in lieu of the default clear icon. @@ -242,7 +241,7 @@ export class Input { }} htmlFor={this.inputId} > - {this.label} + {this.label}
0 + 'form-control--has-label': this.label.length > 0, + 'form-control--valid': this.valid, + 'form-control--invalid': this.invalid }} > - (this.dropdown = el)} @@ -327,9 +322,12 @@ export class Select { value={this.displayLabel} disabled={this.disabled} pill={this.pill} + label={this.label} placeholder={this.displayLabel === '' && this.displayTags.length === 0 ? this.placeholder : null} readonly={true} size={this.size} + valid={this.valid} + invalid={this.invalid} aria-labelledby={this.labelId} onSlFocus={this.handleFocus} onSlBlur={this.handleBlur} @@ -355,6 +353,21 @@ export class Select { + +
+ +
); } diff --git a/src/components/textarea/textarea.tsx b/src/components/textarea/textarea.tsx index 1ebef4350..3b4e18286 100644 --- a/src/components/textarea/textarea.tsx +++ b/src/components/textarea/textarea.tsx @@ -7,8 +7,6 @@ let id = 0; * @since 1.0 * @status stable * - * @slot label - The textarea's label. Alternatively, you can use the label prop. - * * @part base - The component's base wrapper. * @part form-control - The form control that wraps the textarea and label. * @part label - The textarea label. @@ -197,7 +195,7 @@ export class Textarea { }} htmlFor={this.textareaId} > - {this.label} + {this.label}