Skip to content

Commit

Permalink
fix(v-font): fix missing font-active class
Browse files Browse the repository at this point in the history
  • Loading branch information
ThornWalli committed Feb 10, 2024
1 parent 8fe586c commit a16c688
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/runtime/directives/vFont.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ const observers = new Map();
export default {
install(vueApp) {
vueApp.directive('font', {
beforeMount(el, binding, vnode) {
created(el, binding, vnode) {
binding.instance.fontsReady = binding.instance.fontsReady || new Map();
const values = [].concat(binding.value);
if (values.length) {
const { isCritical, fontCollection } = getFirstFont(values);
const definitions = values.map(({ definition }) => definition);
const rootSelector = fontCollection.add(definitions);
vnode.el.setAttribute(rootSelector.name, rootSelector.value);
el.setAttribute(rootSelector.name, rootSelector.value);
binding.instance.fontsReady.set(el, true);
vnode.fontActive = isCritical;
if (typeof vnode.props.class === 'string') {
vnode.props.class = [
...vnode.props.class.split(' '),
isCritical && CLASS_FONT_ACTIVE
]
.filter(Boolean)
.join(' ');
}
}
},

Expand Down

0 comments on commit a16c688

Please sign in to comment.