Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [Numberinput]: Vue Compat: deprecation INSTANCE_ATTRS_CLASS_STYLE (#16) #214

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

* `Numberinput`:

TBD
If `compat-fallthrough` is `true`, the attributes fall through to the root `<div>` element, otherwise to the underlying `<b-input>` component.

* `Select`:

Expand Down
41 changes: 41 additions & 0 deletions packages/buefy-next/src/components/numberinput/Numberinput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,45 @@ describe('BNumberinput', () => {
expect(wrapper.vm.computedValue).toBe(5)
})
})

describe('with fallthrough attributes', () => {
const attrs = {
class: 'fallthrough-class',
style: 'font-size: 2rem;',
id: 'fallthrough-id'
}

it('should apply class, style, and id to the root <div> element if compatFallthrough is true (default)', () => {
const wrapper = shallowMount(BNumberinput, { attrs })

const root = wrapper.find('div.b-numberinput')
expect(root.classes(attrs.class)).toBe(true)
expect(root.attributes('style')).toBe(attrs.style)
expect(root.attributes('id')).toBe(attrs.id)

const input = wrapper.findComponent({ ref: 'input' })
expect(input.classes(attrs.class)).toBe(false)
expect(input.attributes('style')).toBeUndefined()
expect(input.attributes('id')).toBeUndefined()
})

it('should apply class, style and id to the underlying <b-input> if compatFallthrough is false', () => {
const wrapper = shallowMount(BNumberinput, {
attrs,
props: {
compatFallthrough: false
}
})

const root = wrapper.find('div.b-numberinput')
expect(root.classes(attrs.class)).toBe(false)
expect(root.attributes('style')).toBeUndefined()
expect(root.attributes('id')).toBeUndefined()

const input = wrapper.findComponent({ ref: 'input' })
expect(input.classes(attrs.class)).toBe(true)
expect(input.attributes('style')).toBe(attrs.style)
expect(input.attributes('id')).toBe(attrs.id)
})
})
})
12 changes: 8 additions & 4 deletions packages/buefy-next/src/components/numberinput/Numberinput.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<div class="b-numberinput field" :class="fieldClasses">
<div
class="b-numberinput field"
:class="fieldClasses"
v-bind="rootAttrs"
>
<p
v-for="control in controlsLeft"
:key="control"
Expand Down Expand Up @@ -37,7 +41,7 @@
type="number"
ref="input"
v-model="computedValue"
v-bind="$attrs"
v-bind="fallthroughAttrs"
:step="minStepNumber"
:max="max"
:min="min"
Expand Down Expand Up @@ -95,6 +99,7 @@
<script>
import Icon from '../icon/Icon.vue'
import Input from '../input/Input.vue'
import CompatFallthroughMixin from '../../utils/CompatFallthroughMixin'
import FormElementMixin from '../../utils/FormElementMixin'

export default {
Expand All @@ -103,8 +108,7 @@ export default {
[Icon.name]: Icon,
[Input.name]: Input
},
mixins: [FormElementMixin],
inheritAttrs: false,
mixins: [CompatFallthroughMixin, FormElementMixin],
inject: {
field: {
from: 'BField',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ export default [
values: '—',
default: '<code>true</code>'
},
{
name: '<code>compat-fallthrough</code>',
description: 'Whether the <code>class</code>, <code>style</code>, and <code>id</code> attributes are applied to the root &lt;div&gt; element or the underlying &lt;b-input&gt; component. If <code>true</code>, they are applied to the root &lt;div&gt; element, which is compatible with Buefy for Vue 2.',
type: 'Boolean',
values: '-',
default: '<code>true</code>. Can be changed via the <code>defaultCompatFallthrough</code> config option.'
},
{
name: 'Any native attribute',
description: '—',
Expand Down