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

Show method does not show calendar #224

Open
chunhoong opened this issue Jan 30, 2020 · 2 comments
Open

Show method does not show calendar #224

chunhoong opened this issue Jan 30, 2020 · 2 comments

Comments

@chunhoong
Copy link

I am using bulma-calendar in my Vue application. The calendar is not shown after I invoke show method. Here is my code snippet:

sample.vue

<template>
  <div>
    <input ref="calendarTrigger" />

    <button @click="showCalendar">Show the calendar</button>
  </div>
</template>

<script>
import bulmaCalendar from 'bulma-calendar'

export default {
  data() {
    return {
      calendar: null
    }
  },
  methods: {
    showCalendar() {
      this.calendar.show()
    }
  },
  mounted() {
    this.calendar = bulmaCalendar.attach(this.$refs.calendarTrigger, {
      type: 'date',
      displayMode: 'default'
    })[0]
  }
}
</script>
@lakano
Copy link

lakano commented Apr 19, 2020

I have the same problem... did you find a solution @chunhoong ?

@lakano
Copy link

lakano commented Apr 19, 2020

I've created a workaround, I share my solution here:

In your template:

<a class="button" @click="calendarShow($refs.calendarTrigger)">show calendar</a>

In your methods:

methods: {
		/**	
		 * Show the calendar ( workaround of buggy calendar.show() )
		 *
		 *	@param {HTMLElement} cal - The calendarTrigger element
		 */
		calendarShow(cal) {
			this.updateClass(cal.parentNode, 'is-hidden', 'is-active')
			this.updateClass(cal.parentNode.parentNode, 'is-hidden', 'is-active')
			this.updateClass(cal.parentNode.parentNode.parentNode.lastElementChild, 'is-hidden', 'is-active')
		},



		/**	
		 * Update classes of an element
		 *
		 *	@param {HTMLElement} e		- Element
		 *	@param {String} [removeStr]	- List of classes to remove (eg: 'old')
		 *	@param {String} [addStr]	- List of classes to add (eg: 'new addThis')
		 */
		updateClass (e, removeStr, addStr) {

			let classes = e.className.trim().replace('  ', ' ').split(' ')
			if (removeStr) {
				const remove = removeStr.trim().replace('  ', ' ').split(' ')
				for (const r of remove) {
					classes = classes.filter(n => n !== r)
					c.log({ removed: r, classes })
				}
			}
			if (addStr) {
				const add = addStr.trim().replace('  ', ' ').split(' ')
				for (const a of add) {
					classes.push(a)
					c.log({ added: a, classes })
				}
			}
			e.className = classes.join(' ')
		},
}

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