From a0c020f7a8ca02ca74c299f5c6fffd00fd1bf174 Mon Sep 17 00:00:00 2001 From: Marcos Moura Date: Tue, 20 Sep 2016 02:22:17 -0300 Subject: [PATCH] Fix dynamic themes not removing last class --- src/components/mdTheme/index.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/mdTheme/index.js b/src/components/mdTheme/index.js index d2ef03d..d310ec8 100644 --- a/src/components/mdTheme/index.js +++ b/src/components/mdTheme/index.js @@ -120,13 +120,19 @@ export default function install(Vue, themes) { document.body.classList.add('md-theme-default'); - Vue.directive('mdTheme', function(el, bindings) { - let theme = bindings.value; + Vue.directive('mdTheme', (element, { value, oldValue }) => { + let theme = value; + let newClass = 'md-theme-' + theme; + let oldClass = 'md-theme-' + oldValue; - if (theme && registedThemes.indexOf(theme) >= 0) { - el.classList.add('md-theme-' + theme); - } else { - console.warn('Attempted to use unregistered theme "' + theme + '\".'); + if (!element.classList.contains(newClass)) { + element.classList.remove(oldClass); + + if (theme && registedThemes.indexOf(theme) >= 0) { + element.classList.add(newClass); + } else { + console.warn('Attempted to use unregistered theme "' + theme + '\".'); + } } }); }