Skip to content

Commit 373f0d3

Browse files
iOvergaardloivsen
andauthored
fix: Add labels to fix accessibility warnings (#289)
* add labels to storybook fix accessibility warnings * input extends from labelmixin to show correct warnings Co-authored-by: Lone Iversen <[email protected]>
1 parent a089cb1 commit 373f0d3

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

packages/uui-base/lib/mixins/LabelMixin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const LabelMixin = <T extends Constructor<LitElement>>(
2626
*/
2727
class LabelMixinClass extends superClass {
2828
/**
29-
* Label to be used for aria-label and eventually as visual label
29+
* Label to be used for aria-label and potentially as visual label for some components
3030
* @type {string}
3131
* @attr
3232
*/

packages/uui-form-layout-item/lib/uui-form-layout-item.story.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const Example: Story = () => html` <uui-form>
3535
type="text"
3636
name="phone"
3737
placeholder="+00"
38+
label="phone area code"
3839
required
3940
required-message="You must enter a area code"
4041
style="text-align:right; width: 75px;">
@@ -43,6 +44,7 @@ export const Example: Story = () => html` <uui-form>
4344
type="text"
4445
name="phone"
4546
placeholder=""
47+
label="phone number"
4648
required
4749
required-message="You must enter a phone number">
4850
</uui-input>
@@ -55,8 +57,9 @@ export const Example: Story = () => html` <uui-form>
5557
<uui-input
5658
id="cityinput"
5759
type="text"
58-
name="phone"
60+
name="city"
5961
placeholder=""
62+
label="city"
6063
required
6164
required-message="You must enter a city">
6265
</uui-input>
@@ -68,6 +71,7 @@ export const Example: Story = () => html` <uui-form>
6871
type="text"
6972
name="postal"
7073
placeholder=""
74+
label="postal number"
7175
required
7276
required-message="You must enter a postal number">
7377
</uui-input>

packages/uui-input/lib/uui-input.element.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FormControlMixin } from '@umbraco-ui/uui-base/lib/mixins';
1+
import { FormControlMixin, LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
22
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
33
import { css, html, LitElement, PropertyValueMap } from 'lit';
44
import { property, query } from 'lit/decorators.js';
@@ -23,15 +23,16 @@ export type InputType =
2323
/**
2424
* Custom element wrapping the native input element.This is a formAssociated element, meaning it can participate in a native HTMLForm. A name:value pair will be submitted.
2525
* @element uui-input
26-
* @slot input label - for the input label text.
2726
* @slot prepend - for components to render to the left of the input.
2827
* @slot append - for components to render to the right of the input.
2928
* @fires UUIInputEvent#change on change
3029
* @fires InputEvent#input on input
3130
* @fires KeyboardEvent#keyup on keyup
3231
*/
3332
@defineElement('uui-input')
34-
export class UUIInputElement extends FormControlMixin(LitElement) {
33+
export class UUIInputElement extends FormControlMixin(
34+
LabelMixin('', LitElement)
35+
) {
3536
/**
3637
* This is a static class field indicating that the element is can be used inside a native form and participate in its events. It may require a polyfill, check support here https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals. Read more about form controls here https://web.dev/more-capable-form-controls/
3738
* @type {boolean}
@@ -195,14 +196,6 @@ export class UUIInputElement extends FormControlMixin(LitElement) {
195196
@property({ type: Boolean, reflect: true })
196197
readonly = false;
197198

198-
/**
199-
* Label for input element.
200-
* @type {string}
201-
* @attr
202-
*/
203-
@property({ type: String })
204-
public label!: string;
205-
206199
/**
207200
* Defines the input placeholder.
208201
* @type {string}

0 commit comments

Comments
 (0)