Skip to content

Instantly share code, notes, and snippets.

@trezy
Last active March 27, 2019 18:53
Show Gist options
  • Save trezy/10f80c7befeb2f409e5d4ecd4de93c14 to your computer and use it in GitHub Desktop.
Save trezy/10f80c7befeb2f409e5d4ecd4de93c14 to your computer and use it in GitHub Desktop.
Weird Nuxt SSR issue
<template>
<div class="collapsable">
<input
:id="`${id}::collapsable-control`"
:name="[`${group}`]"
:type="[`${group ? 'radio' : 'checkbox'}`]" />
<label
v-on:click="handleClick"
:for="`${id}::collapsable-control`">
<slot name="control" />
</label>
<div :class="`collapsable-child ${childClasses}`">
<slot name="child" />
</div>
</div>
</template>
<script>
import uuid from 'uuid/v4'
export default {
methods: {
handleClick: ({ target }) => {
const controlID = target.getAttribute('for')
const controlElement = document.querySelector(`[id='${controlID}']`)
// eslint-disable-next-line
console.log('controlElement', controlElement)
if (controlElement && controlElement.checked) {
controlElement.checked = false
}
},
},
props: {
childClasses: {
default: null,
type: String,
},
group: {
default: '',
type: String,
},
id: {
default: () => uuid(),
type: String,
},
},
}
</script>
<template>
<Collapsable>
<template v-slot:control>
Label
</template>
<template v-slot:child>
Content
</template>
</Collapsable>
</template>
<script>
import Collapsable from './Collapsable.vue'
export default {
components: {
Collapsable,
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment