Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
rakieta2015 committed Oct 26, 2020
2 parents 93211e0 + 9c4da02 commit a066590
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@coreui/vue",
"description": "CoreUI Vue Bootstrap 4 layout components",
"version": "3.1.2",
"version": "3.1.3",
"license": "MIT",
"main": "dist/coreui-vue.common.js",
"types": "src/index.d.ts",
Expand Down
4 changes: 3 additions & 1 deletion src/components/grid/CCol.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
md: [ Boolean, String, Number, Object ],
lg: [ Boolean, String, Number, Object ],
xl: [ Boolean, String, Number, Object ],
xxl: [ Boolean, String, Number, Object ],
tag: {
type: String,
default: 'div'
Expand All @@ -24,7 +25,8 @@ export default {
'sm': '-sm',
'md': '-md',
'lg': '-lg',
'xl': '-xl'
'xl': '-xl',
'xxl': '-xxl',
}
Object.keys(suffixes).forEach((key) => {
const prop = props[key]
Expand Down
3 changes: 2 additions & 1 deletion src/components/grid/tests/CCol.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const customWrapper = mount(Component, {
sm: 12,
md: { size: 6, offset: 3, order: 1},
lg: {},
xl: true
xl: true,
xxl: { size: 4, offset: 2, order: 1}
},
slots: {
default: 'CCol content'
Expand Down
2 changes: 1 addition & 1 deletion src/components/grid/tests/__snapshots__/CCol.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`CCol renders correctly 1`] = `

exports[`CCol renders correctly 2`] = `
<div
class="col-sm-12 col-md-6 offset-md-3 order-md-1 col-xl"
class="col-sm-12 col-md-6 offset-md-3 order-md-1 col-xl col-xxl-4 offset-xxl-2 order-xxl-1"
>
<template>
CCol content
Expand Down
1 change: 1 addition & 0 deletions src/components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export declare class CCol extends Vue {
md?: boolean | string | number | object
lg?: boolean | string | number | object
xl?: boolean | string | number | object
xxl?: boolean | string | number | object
tag?: string
}

Expand Down
25 changes: 24 additions & 1 deletion src/components/modal/CModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export default {
type: Boolean,
default: true
},
addContentClasses: [String, Array, Object]
addContentClasses: [String, Array, Object],
onKey: Function,
},
data () {
return {
Expand Down Expand Up @@ -147,9 +148,26 @@ export default {
},
hide (e, accept = false) {
this.$emit('update:show', false, e, accept)
if(this.visible){
window.removeEventListener("keydown", this.hideEsc );
}
},
hideEsc (event){
if(typeof this.onKey != 'undefined'){
if(this.onKey('', event.keyCode)!==false){
this.hide(event)
}
}else{
if(event.keyCode == '27'){
this.hide(event)
}
}
},
toggle (newVal) {
setTimeout(() => { this.visible = newVal }, 0)
if(newVal){
window.addEventListener('keydown', this.hideEsc );
}
if (this.fade) {
this.isTransitioning = true
clearTimeout(this.timeout)
Expand All @@ -158,6 +176,11 @@ export default {
}, 150)
}
}
},
mounted: function(){
if(this.show){
window.addEventListener('keydown', this.hideEsc );
}
}
}
</script>
25 changes: 23 additions & 2 deletions src/components/modal/tests/CModal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { mount } from '@vue/test-utils'
import Component from '../CModal'

const ComponentName = 'CModal'
const defaultWrapper = mount(Component)
const defaultWrapper = mount(Component, { attachToDocument: true })
const defaultWrapper2 = mount(Component, {
propsData: {
show: true,
onKey: function(type, key){
return key===32
}
},
attachToDocument: true
})
const customWrapper = mount(Component, {
propsData: {
show: true,
Expand All @@ -14,7 +23,7 @@ const customWrapper = mount(Component, {
fade: true,
backdrop: true,
closeOnBackdrop: false,
addContentClasses: 'additional-content-class'
addContentClasses: 'additional-content-class',
},
slots: {
default: 'CModal body'
Expand Down Expand Up @@ -58,4 +67,16 @@ describe(ComponentName, () => {
}, 200)
jest.runAllTimers()
})
it('Close on default key -> ESC (modal donot show=true on mounted)', () => {
defaultWrapper.setProps(
{
show: true,
})
defaultWrapper.trigger('keydown.esc')
expect(defaultWrapper.emitted()['update:show']).toBeTruthy()
})
it('Close on key defined in onKey function (modal show=true on mounted)', () => {
defaultWrapper2.trigger('keydown.space')
expect(defaultWrapper2.emitted()['update:show']).toBeTruthy()
})
})

0 comments on commit a066590

Please sign in to comment.