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

Issue with vs-switch $refs.on and $refs.off #726

Open
lk77 opened this issue Dec 5, 2019 · 2 comments
Open

Issue with vs-switch $refs.on and $refs.off #726

lk77 opened this issue Dec 5, 2019 · 2 comments

Comments

@lk77
Copy link
Contributor

lk77 commented Dec 5, 2019

Your OS : Ubuntu 18.10 (Issue seems to be on mac os x)
Node.js version 11.10.1
Vuesax version 3.11.1
Browser version chrome 78
Which package manager did you use for the install? npm

Hello,

i have an issue with vs-switch :

Cannot read property 'clientWidth' of undefined

it seems related to $refs.on and $refs.off in mounted hook inside vs-switch.
Sometimes it's not defined

The data i have :

componentName component at vsSwitch.vue
lifecycleHook nextTick
propsData {color: #ea5455, iconPack: feather, value: False, vsIconOff: icon-unlock, vsIconOn: icon-lock}
Name Mac OS X
Version 10.15.1
name Chrome
version 78.0.3904

thanks.

@iomariani
Copy link
Contributor

I had the same issue, but instead with VsPrompt.

This happens because it tries to find find the button to change the click animation, but when nextTick happens the button does not exist anymore.

The issue is at

let btn = this.$refs.btn
let xEvent = event.offsetX
let yEvent = event.offsetY
let radio = btn.clientWidth * 3
this.time = btn.clientWidth / (btn.clientWidth + (this.is('border') || this.is('flat') ? 70 : 20))
if(this.is('filled')){
this.timeOpacity = this.time
}
if(event.srcElement ? event.srcElement != btn : false) {
xEvent += event.target.offsetLeft
yEvent += event.target.offsetTop
}
this.leftBackgorund = xEvent
this.topBackgorund = yEvent
this.radio = radio
if(this.is('filled')){
this.opacity = 0
} else {
this.opacity = 1
}
if(this.is('filled')){
setTimeout( () => {
this.time = this.timeOpacity = this.radio = 0
this.opacity = 1
this.isActive = false
}, this.time * 1100)
} else {
setTimeout( () => {
this.timeOpacity = .15
}, this.time * 1100)
}

This entire block should be wrapped with an if first

if (this.$refs.btn) {
 ...
}

@iomariani
Copy link
Contributor

Seem it's also related to #611

iomariani added a commit to iomariani/vuesax that referenced this issue Oct 7, 2020
*Bug:* Whenever the click of a VsButton happens it triggers a nextTick, but if the button does not exist anymore there will throw the error:
`Cannot read property 'clientWidth' of undefined`

*Fix: * Check if button reference still exists when nextTick happens.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants