Skip to content

Commit

Permalink
Fix [Taginput]: Vue Compat: deprecation INSTANCE_ATTRS_CLASS_STYLE (#16
Browse files Browse the repository at this point in the history
…) (#218)

* feat(lib): add compat-fallthrough prop to Taginput

- `Taginput` introduces a new prop `compat-fallthrough` which determines
  the `class`, `style`, and `id` attributes are applied to the root
  `<div>` element or the underlying `<b-autocomplete>` component. Since
  Vue 3 changed the fallthrough behavior, `Taginput` became incompatible
  with that of Buefy for Vue 2. The default value of this prop is given
  by the `defaultCompatFallthrough` config option that is `true` by
  default (compatible with Buefy for Vue 2).

* test(lib): test Taginput fallthrough behavior

- Adds test cases for the `compat-fallthrough` prop of `Taginput`

* chore(docs): explain compat-fallthrough prop of Taginput

* docs(CHANGELOG): explain compat-fallthrough prop of Taginput
  • Loading branch information
kikuomax authored Mar 29, 2024
1 parent 8addee9 commit 1ad2aaf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

* `Taginput`:

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

* `Timepicker`:

Expand Down
41 changes: 41 additions & 0 deletions packages/buefy-next/src/components/taginput/Taginput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,45 @@ describe('BTaginput', () => {
expect(firedHeader).toBeTruthy()
expect(firedFooter).toBeTruthy()
})

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(BTaginput, { attrs })

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

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

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

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

const autocomplete = wrapper.findComponent({ ref: 'autocomplete' })
expect(autocomplete.classes(attrs.class)).toBe(true)
expect(autocomplete.attributes('style')).toBe(attrs.style)
expect(autocomplete.attributes('id')).toBe(attrs.id)
})
})
})
12 changes: 8 additions & 4 deletions packages/buefy-next/src/components/taginput/Taginput.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<div class="taginput control" :class="rootClasses">
<div
class="taginput control"
:class="rootClasses"
v-bind="rootAttrs"
>
<div
class="taginput-container"
:class="[statusType, size, containerClasses]"
Expand Down Expand Up @@ -33,7 +37,7 @@
ref="autocomplete"
v-if="hasInput"
v-model="newTag"
v-bind="$attrs"
v-bind="fallthroughAttrs"
:data="data"
:field="field"
:icon="icon"
Expand Down Expand Up @@ -108,6 +112,7 @@ import { getValueByPath } from '../../utils/helpers'
import Tag from '../tag/Tag.vue'
import Autocomplete from '../autocomplete/Autocomplete.vue'
import config from '../../utils/config'
import CompatFallthroughMixin from '../../utils/CompatFallthroughMixin'
import FormElementMixin from '../../utils/FormElementMixin'
export default {
Expand All @@ -116,8 +121,7 @@ export default {
[Autocomplete.name]: Autocomplete,
[Tag.name]: Tag
},
mixins: [FormElementMixin],
inheritAttrs: false,
mixins: [CompatFallthroughMixin, FormElementMixin],
props: {
modelValue: {
type: Array,
Expand Down
7 changes: 7 additions & 0 deletions packages/docs/src/pages/components/taginput/api/taginput.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ export default [
values: '—',
default: '<code>false</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-autocomplete&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 other native attribute',
description: '—',
Expand Down

0 comments on commit 1ad2aaf

Please sign in to comment.