Skip to content

Commit

Permalink
fix: remove attrs bind & css on wrapper if dynamic component
Browse files Browse the repository at this point in the history
  • Loading branch information
14nrv committed Apr 12, 2021
1 parent 42779b2 commit 4e8d764
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 7 additions & 11 deletions src/components/Fields/Control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
:immediate="!!item.value"
v-slot="{ errors, ariaInput }")

.control(:class="{'has-icons-left': item.iconLeft, 'has-icons-right': shouldShowErrorIcon}")
div(:class="{ 'control': !dynamicComponent, 'has-icons-left': item.iconLeft, 'has-icons-right': shouldShowErrorIcon }")
component(v-model.lazy.trim="value",
v-bind="getDynamicComponentAttrs"
:item="item",
:is="dynamicComponent || `app-${getComponent}`",
:error="errors[0]",
:ariaInput="ariaInput")

span.icon.is-small.is-left(v-if="item.iconLeft")
i.fas(:class="`fa-${item.iconLeft}`")
span.icon.is-small.is-right(v-if="shouldShowErrorIcon")
i.fas.fa-exclamation-triangle
p.help.is-danger(v-if="errors.length") {{ errors[0] }}
span(v-if="!dynamicComponent")
span.icon.is-small.is-left(v-if="item.iconLeft")
i.fas(:class="`fa-${item.iconLeft}`")
span.icon.is-small.is-right(v-if="shouldShowErrorIcon")
i.fas.fa-exclamation-triangle
p.help.is-danger(v-if="errors.length") {{ errors[0] }}
</template>

<script>
Expand Down Expand Up @@ -84,10 +84,6 @@ export default {
getComponent () {
return this.isNormalInput ? 'input' : this.item.type
},
getDynamicComponentAttrs () {
const { is, attr } = this.item
return is && attr ? attr : {}
},
getRules () {
const { rules = {}, pattern } = this.item
rules.required = this.item.isRequired !== false
Expand Down
6 changes: 5 additions & 1 deletion src/components/Form/FormComponent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const CustomField = Vue.component('CustomField', {
item: {
type: Object,
required: true
},
error: {
type: String,
default: null
}
},
mounted () {
Expand All @@ -50,7 +54,7 @@ const CustomField = Vue.component('CustomField', {
}
},
render (h) {
return <input vOn:input={ this.handleClick } />
return <div><input vOn:input={this.handleClick} attrs={this.item.attr} /><p class="is-danger">{ this.error }</p></div>
}
})

Expand Down
6 changes: 3 additions & 3 deletions src/components/Form/FormError.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ describe('Form Error', () => {
it('show error if input value has not min length', async () => {
const LABEL_INPUT_SLUGIFY = slug(LABEL_INPUT)
const $inputTest = `input[name=${LABEL_INPUT_SLUGIFY}]`
const $error = `${$inputTest} ~ .help.is-danger`
const $error = `${$inputTest} ~ span .help.is-danger`

expect($error).not.toBeADomElement()

type('123456789', $inputTest)
await flush()

expect('.is-danger').toBeADomElement()
expect(`${$inputTest} ~ .icon.is-right`).toBeADomElement()
expect(`${$inputTest} ~ span .icon.is-right`).toBeADomElement()

expect($error).toHaveText(`The ${LABEL_INPUT_SLUGIFY} field must be at least ${MIN_LENGTH} characters`, $error)

Expand All @@ -86,7 +86,7 @@ describe('Form Error', () => {

it(`set ${isMinValue ? 'min' : 'max'} value control on input number`, async () => {
const inputValue = (isMinValue ? val - 1 : val + 1).toString()
const $error = `${INPUT_NUMBER} ~ .help.is-danger`
const $error = `${INPUT_NUMBER} ~ span .help.is-danger`

type(inputValue, INPUT_NUMBER)
expect(INPUT_NUMBER).toHaveValue(inputValue)
Expand Down

0 comments on commit 4e8d764

Please sign in to comment.