Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Emit an 'open' event when the popup is opened #271

Open
wants to merge 2 commits into
base: v1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ Settings.defaultLocale = 'es'

Component emits the `input` event to work with `v-model`. [More info](https://vuejs.org/v2/guide/components.html#Form-Input-Components-using-Custom-Events).

`open` event is emitted when the popup opens.

`close` event is emitted when the popup closes.

Also, input text inherits all component events.
Expand Down
2 changes: 2 additions & 0 deletions src/Datetime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ export default {
event.target.blur()

this.isOpen = true

this.$emit('open')
},
close () {
this.isOpen = false
Expand Down
21 changes: 21 additions & 0 deletions test/specs/Datetime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,27 @@ describe('Datetime.vue', function () {
})
})

it('should emit open when popup opens', function (done) {
const vm = createVM(this,
`<Datetime @open="spy"></Datetime>`,
{
components: { Datetime },
data () {
return {
spy: sinon.spy()
}
}
})

expect(vm.spy).to.have.not.been.called
vm.$('.vdatetime-input').click()

vm.$nextTick(() => {
expect(vm.spy).to.have.been.calledOnce
done()
})
})

it('should emit close when popup closes', function (done) {
const vm = createVM(this,
`<Datetime @close="spy"></Datetime>`,
Expand Down
2 changes: 1 addition & 1 deletion test/specs/DatetimeCalendar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('DatetimeCalendar.vue', function () {
expect(vm.$('.vdatetime-calendar__current--month')).to.have.text('Julio 2018')

const weekdays = vm.$$('.vdatetime-calendar__month__weekday').map(el => el.textContent)
expect(weekdays).deep.equal(['Lun.', 'Mar.', 'Mié.', 'Jue.', 'Vie.', 'Sáb.', 'Dom.'])
expect(weekdays).deep.equal(['Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb', 'Dom'])
})

it('should render a calendar with other week start', function () {
Expand Down