Skip to content

Commit

Permalink
Merge pull request #4225 from nextcloud/enh/input-field-describedby
Browse files Browse the repository at this point in the history
Append custom aria-describedby to input field
  • Loading branch information
raimund-schluessler committed Jun 16, 2023
2 parents d87b428 + 637ece9 commit afc836c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/NcInputField/NcInputField.vue
Expand Up @@ -48,7 +48,7 @@ For a list of all available props and attributes, please check the [HTMLInputEle
:type="type"
:disabled="disabled"
:placeholder="computedPlaceholder"
:aria-describedby="helperText.length > 0 ? `${inputName}-helper-text` : ''"
:aria-describedby="ariaDescribedby"
aria-live="polite"
:class="[inputClass,
{
Expand Down Expand Up @@ -283,13 +283,25 @@ export default {
return this.hasPlaceholder ? this.placeholder : this.label
}
},
isValidLabel() {
const isValidLabel = this.label || this.labelOutside
if (!isValidLabel) {
console.warn('You need to add a label to the NcInputField component. Either use the prop label or use an external one, as per the example in the documentation.')
}
return isValidLabel
},
ariaDescribedby() {
const ariaDescribedby = []
if (this.helperText.length > 0) {
ariaDescribedby.push(`${this.inputName}-helper-text`)
}
if (this.$attrs['aria-describedby']) {
ariaDescribedby.push(this.$attrs['aria-describedby'])
}
return ariaDescribedby.join(' ') || null
},
},
methods: {
Expand Down

0 comments on commit afc836c

Please sign in to comment.