Skip to content

Commit

Permalink
feat: input-number: pass through aria-label to inner input-text
Browse files Browse the repository at this point in the history
  • Loading branch information
margaree committed Sep 26, 2024
1 parent 3a1da26 commit 44d28ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/inputs/demo/input-number.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ <h2>Hidden Label</h2>
<d2l-input-number label="Age" label-hidden></d2l-input-number>
</template>
</d2l-demo-snippet>

<h2>Hidden Label Different from Visible Label</h2>
<d2l-demo-snippet>
<template>
<d2l-input-number label="Age" hidden-label="Age (number)"></d2l-input-number>
</template>
</d2l-demo-snippet>

<h2>Required</h2>
<d2l-demo-snippet>
Expand Down
12 changes: 12 additions & 0 deletions components/inputs/input-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ class InputNumber extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixi
* @type {boolean}
*/
disabled: { type: Boolean },
/**
* ACCESSIBILITY: Hidden label, different from `label`, to be used on the input to provide more context for screenreader users.
* To be used only if `label` is defined and `label-hidden` is NOT used.
* Note that screenreader users will likely NOT hear the `label`.
* @type {string}
*/
hiddenLabel: { attribute: 'hidden-label', type: String },
/**
* ADVANCED: Hide the alert icon when input is invalid
* @type {boolean}
Expand Down Expand Up @@ -333,12 +340,17 @@ class InputNumber extends FocusMixin(LabelledMixin(SkeletonMixin(FormElementMixi
this._updateFormattedValue();
}
});

if (this.hiddenLabel && this.label && this.labelHidden) {
console.warn('d2l-input-number: Define the label with only label and label-hidden');
}
}

render() {
const valueAlign = (this.valueAlign === 'end') ? 'end' : 'start';
return html`
<d2l-input-text
aria-label="${ifDefined(this.hiddenLabel)}"
autocomplete="${ifDefined(this.autocomplete)}"
?noValidate="${this.noValidate}"
?autofocus="${this.autofocus}"
Expand Down

0 comments on commit 44d28ad

Please sign in to comment.