Skip to content

Commit

Permalink
Merge pull request #3980 from nextcloud/fix/noid/inverted-label-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Pytal authored Apr 18, 2023
2 parents a4e9aff + 842639f commit 537e85b
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/components/NcInputField/NcInputField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ For a list of all available props and attributes, please check the [HTMLInputEle

<template>
<div class="input-field">
<label v-if="!labelOutside && label !== undefined"
<label v-if="!labelOutside && isValidLabel"
class="input-field__label"
:class="{ 'input-field__label--hidden': !labelVisible }"
:for="computedId">
Expand Down Expand Up @@ -283,15 +283,12 @@ export default {
return this.hasPlaceholder ? this.placeholder : this.label
}
},
},

watch: {
label() {
this.validateLabel()
},

labelOutside() {
this.validateLabel()
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
},
},

Expand All @@ -303,12 +300,6 @@ export default {
handleTrailingButtonClick(event) {
this.$emit('trailing-button-click', event)
},

validateLabel() {
if (this.label && !this.labelOutside) {
throw new Error('You need to add a label to the textField component. Either use the prop label or use an external one, as per the example in the documentation')
}
},
},
}
</script>
Expand Down

0 comments on commit 537e85b

Please sign in to comment.