|
3 | 3 | DEFAULT_VALIDATION_MESSAGE_TYPE, |
4 | 4 | VALIDATION_MESSAGE_TYPES, |
5 | 5 | } from '../constants'; |
| 6 | +import { |
| 7 | + configVue2StyleClassAttrs, |
| 8 | +} from '../config'; |
6 | 9 | import { |
7 | 10 | h, |
8 | 11 | Comment, |
@@ -219,6 +222,39 @@ export const returnFirstEl = (el) => { |
219 | 222 | } |
220 | 223 | }; |
221 | 224 |
|
| 225 | +/** |
| 226 | + Only will apply changes if the config option configVue2StyleClassAttrs is set to true. It is false by default. |
| 227 | +
|
| 228 | + Removes the class and style attributes from the $attrs. This is useful for vue 2 to vue 3 migration |
| 229 | + purposes so we don't cause breaking changes due to INSTANCE_ATTRS_CLASS_STYLE |
| 230 | + https://v3-migration.vuejs.org/breaking-changes/attrs-includes-class-style |
| 231 | +
|
| 232 | + Remove the class and style attributes from the v-bind like so so v-bind="removeClassStyleAttrs($attrs)", |
| 233 | + and then apply them to the root element manually via: |
| 234 | +
|
| 235 | + :class="$attrs.class" |
| 236 | + :style="$attrs.style" |
| 237 | +*/ |
| 238 | +export function removeClassStyleAttrs (attrs) { |
| 239 | + if (!configVue2StyleClassAttrs) return attrs; |
| 240 | + const listeners = Object.entries(attrs) |
| 241 | + .filter(([key]) => !['class', 'style'].includes(key)); |
| 242 | + return Object.fromEntries(listeners); |
| 243 | +} |
| 244 | + |
| 245 | +/** |
| 246 | + This should be applied to the root element on components using inheritAttrs: false. |
| 247 | + This will add the class and style attributes back to the root element if configVue2StyleClassAttrs |
| 248 | + is enabled. |
| 249 | +*/ |
| 250 | +export function addClassStyleAttrs (attrs) { |
| 251 | + if (!configVue2StyleClassAttrs) return {}; |
| 252 | + return { |
| 253 | + class: attrs.class, |
| 254 | + style: attrs.style, |
| 255 | + }; |
| 256 | +} |
| 257 | + |
222 | 258 | /* |
223 | 259 | * Set's a global timer to debounce the execution of a function. |
224 | 260 | * @param { object } func - the function that is going to be called after timeout |
@@ -473,6 +509,8 @@ export default { |
473 | 509 | flushPromises, |
474 | 510 | kebabCaseToPascalCase, |
475 | 511 | extractVueListeners, |
| 512 | + removeClassStyleAttrs, |
| 513 | + addClassStyleAttrs, |
476 | 514 | returnFirstEl, |
477 | 515 | debounce, |
478 | 516 | isOutOfViewPort, |
|
0 commit comments