@tak-ps/vue-tabler 5.7.0 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/components/Modal.vue +16 -2
- package/package.json +1 -1
- package/test/Modal.spec.ts +58 -0
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
### Pending
|
|
14
14
|
|
|
15
|
+
### v5.8.0 - 2026-09-21
|
|
16
|
+
|
|
17
|
+
- :tada: Add a `dismissable` prop to `TablerModal`, off by default, that emits `close` when the backdrop is clicked
|
|
18
|
+
- :white_check_mark: Add `TablerModal` tests
|
|
19
|
+
|
|
15
20
|
### v5.7.0 - 2026-09-18
|
|
16
21
|
|
|
17
22
|
- :tada: Add `TablerMarkdownEditor`, a WYSIWYG Markdown editor built on Tiptap with a formatting toolbar & table editing. It is `v-model`'d with a Markdown string, emits `submit` on `Ctrl/Cmd+Enter` and is exported as an async component so ProseMirror is only loaded when an editor is first rendered
|
package/components/Modal.vue
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
style='display: block;'
|
|
14
14
|
aria-modal='true'
|
|
15
15
|
role='dialog'
|
|
16
|
+
@mousedown='pressed = $event.target'
|
|
17
|
+
@click.self='clickAway'
|
|
16
18
|
>
|
|
17
19
|
<div
|
|
18
20
|
class='modal-dialog modal-dialog-centered'
|
|
@@ -39,14 +41,26 @@ import { ref, onMounted, nextTick } from 'vue'
|
|
|
39
41
|
export interface ModalProps {
|
|
40
42
|
size?: 'sm' | 'md' | 'lg' | 'xl';
|
|
41
43
|
fade?: boolean;
|
|
44
|
+
dismissable?: boolean;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
withDefaults(defineProps<ModalProps>(), {
|
|
47
|
+
const props = withDefaults(defineProps<ModalProps>(), {
|
|
45
48
|
size: 'sm',
|
|
46
|
-
fade: true
|
|
49
|
+
fade: true,
|
|
50
|
+
dismissable: false
|
|
47
51
|
});
|
|
48
52
|
|
|
53
|
+
const emit = defineEmits<{
|
|
54
|
+
(e: 'close'): void
|
|
55
|
+
}>()
|
|
56
|
+
|
|
49
57
|
const modal = ref<HTMLElement | null>(null)
|
|
58
|
+
const pressed = ref<EventTarget | null>(null)
|
|
59
|
+
|
|
60
|
+
// Ignore drags that start inside the dialog and end on the backdrop
|
|
61
|
+
const clickAway = () => {
|
|
62
|
+
if (props.dismissable && pressed.value === modal.value) emit('close')
|
|
63
|
+
}
|
|
50
64
|
|
|
51
65
|
onMounted(() => {
|
|
52
66
|
nextTick(() => {
|
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { mount, VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import Modal from '../components/Modal.vue'
|
|
4
|
+
|
|
5
|
+
let wrapper: VueWrapper | undefined
|
|
6
|
+
|
|
7
|
+
const mountModal = (props: Record<string, unknown> = {}) => {
|
|
8
|
+
wrapper = mount(Modal, {
|
|
9
|
+
props: { fade: false, ...props },
|
|
10
|
+
slots: { default: '<div class="modal-body">Body</div>' },
|
|
11
|
+
attachTo: document.body,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return wrapper
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const click = (down: Element, up: Element = down) => {
|
|
18
|
+
down.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }))
|
|
19
|
+
up.dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('TablerModal', () => {
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
wrapper?.unmount()
|
|
25
|
+
wrapper = undefined
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('does not emit close on a backdrop click by default', () => {
|
|
29
|
+
const modal = mountModal()
|
|
30
|
+
click(document.body.querySelector('.modal') as Element)
|
|
31
|
+
|
|
32
|
+
expect(modal.emitted('close')).toBeUndefined()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('emits close on a backdrop click when dismissable', () => {
|
|
36
|
+
const modal = mountModal({ dismissable: true })
|
|
37
|
+
click(document.body.querySelector('.modal') as Element)
|
|
38
|
+
|
|
39
|
+
expect(modal.emitted('close')).toHaveLength(1)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('does not emit close for a click inside of the dialog', () => {
|
|
43
|
+
const modal = mountModal({ dismissable: true })
|
|
44
|
+
click(document.body.querySelector('.modal-body') as Element)
|
|
45
|
+
|
|
46
|
+
expect(modal.emitted('close')).toBeUndefined()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('does not emit close for a drag from the dialog onto the backdrop', () => {
|
|
50
|
+
const modal = mountModal({ dismissable: true })
|
|
51
|
+
click(
|
|
52
|
+
document.body.querySelector('.modal-body') as Element,
|
|
53
|
+
document.body.querySelector('.modal') as Element,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
expect(modal.emitted('close')).toBeUndefined()
|
|
57
|
+
})
|
|
58
|
+
})
|