Skip to content

Commit 539bc2e

Browse files
committed
fix: CCol and CModal
1 parent 3c8c082 commit 539bc2e

File tree

6 files changed

+54
-6
lines changed

6 files changed

+54
-6
lines changed

src/components/grid/CCol.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default {
1111
md: [ Boolean, String, Number, Object ],
1212
lg: [ Boolean, String, Number, Object ],
1313
xl: [ Boolean, String, Number, Object ],
14+
xxl: [ Boolean, String, Number, Object ],
1415
tag: {
1516
type: String,
1617
default: 'div'
@@ -24,7 +25,8 @@ export default {
2425
'sm': '-sm',
2526
'md': '-md',
2627
'lg': '-lg',
27-
'xl': '-xl'
28+
'xl': '-xl',
29+
'xxl': '-xxl',
2830
}
2931
Object.keys(suffixes).forEach((key) => {
3032
const prop = props[key]

src/components/grid/tests/CCol.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const customWrapper = mount(Component, {
99
sm: 12,
1010
md: { size: 6, offset: 3, order: 1},
1111
lg: {},
12-
xl: true
12+
xl: true,
13+
xxl: { size: 4, offset: 2, order: 1}
1314
},
1415
slots: {
1516
default: 'CCol content'

src/components/grid/tests/__snapshots__/CCol.spec.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports[`CCol renders correctly 1`] = `
88

99
exports[`CCol renders correctly 2`] = `
1010
<div
11-
class="col-sm-12 col-md-6 offset-md-3 order-md-1 col-xl"
11+
class="col-sm-12 col-md-6 offset-md-3 order-md-1 col-xl col-xxl-4 offset-xxl-2 order-xxl-1"
1212
>
1313
<template>
1414
CCol content

src/components/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export declare class CCol extends Vue {
286286
md?: boolean | string | number | object
287287
lg?: boolean | string | number | object
288288
xl?: boolean | string | number | object
289+
xxl?: boolean | string | number | object
289290
tag?: string
290291
}
291292

src/components/modal/CModal.vue

+24-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export default {
8484
type: Boolean,
8585
default: true
8686
},
87-
addContentClasses: [String, Array, Object]
87+
addContentClasses: [String, Array, Object],
88+
onKey: Function,
8889
},
8990
data () {
9091
return {
@@ -147,9 +148,26 @@ export default {
147148
},
148149
hide (e, accept = false) {
149150
this.$emit('update:show', false, e, accept)
151+
if(this.visible){
152+
window.removeEventListener("keydown", this.hideEsc );
153+
}
154+
},
155+
hideEsc (event){
156+
if(typeof this.onKey != 'undefined'){
157+
if(this.onKey('', event.keyCode)!==false){
158+
this.hide(event)
159+
}
160+
}else{
161+
if(event.keyCode == '27'){
162+
this.hide(event)
163+
}
164+
}
150165
},
151166
toggle (newVal) {
152167
setTimeout(() => { this.visible = newVal }, 0)
168+
if(newVal){
169+
window.addEventListener('keydown', this.hideEsc );
170+
}
153171
if (this.fade) {
154172
this.isTransitioning = true
155173
clearTimeout(this.timeout)
@@ -158,6 +176,11 @@ export default {
158176
}, 150)
159177
}
160178
}
179+
},
180+
mounted: function(){
181+
if(this.show){
182+
window.addEventListener('keydown', this.hideEsc );
183+
}
161184
}
162185
}
163186
</script>

src/components/modal/tests/CModal.spec.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { mount } from '@vue/test-utils'
22
import Component from '../CModal'
33

44
const ComponentName = 'CModal'
5-
const defaultWrapper = mount(Component)
5+
const defaultWrapper = mount(Component, { attachToDocument: true })
6+
const defaultWrapper2 = mount(Component, {
7+
propsData: {
8+
show: true,
9+
onKey: function(type, key){
10+
return key===32
11+
}
12+
},
13+
attachToDocument: true
14+
})
615
const customWrapper = mount(Component, {
716
propsData: {
817
show: true,
@@ -14,7 +23,7 @@ const customWrapper = mount(Component, {
1423
fade: true,
1524
backdrop: true,
1625
closeOnBackdrop: false,
17-
addContentClasses: 'additional-content-class'
26+
addContentClasses: 'additional-content-class',
1827
},
1928
slots: {
2029
default: 'CModal body'
@@ -58,4 +67,16 @@ describe(ComponentName, () => {
5867
}, 200)
5968
jest.runAllTimers()
6069
})
70+
it('Close on default key -> ESC (modal donot show=true on mounted)', () => {
71+
defaultWrapper.setProps(
72+
{
73+
show: true,
74+
})
75+
defaultWrapper.trigger('keydown.esc')
76+
expect(defaultWrapper.emitted()['update:show']).toBeTruthy()
77+
})
78+
it('Close on key defined in onKey function (modal show=true on mounted)', () => {
79+
defaultWrapper2.trigger('keydown.space')
80+
expect(defaultWrapper2.emitted()['update:show']).toBeTruthy()
81+
})
6182
})

0 commit comments

Comments
 (0)