Skip to content

Commit

Permalink
fix: updated eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
kouts committed Jun 25, 2022
1 parent 607c9fd commit b7abcb7
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 13 deletions.
19 changes: 18 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
module.exports = {
extends: ['eslint-config-kouts/vue3']
extends: ['eslint-config-kouts/vue3'],
overrides: [
{
// Disable multi-word-component-names
files: ['playground/**/*.{vue,js}', 'src/**/*.vue', 'docs/**/*.{vue,js}'],
rules: {
'vue/multi-word-component-names': 'off',
'vue/v-on-event-hyphenation': [
'error',
'always',
{
autofix: false,
ignore: ['update:modelValue']
}
]
}
}
]
}
2 changes: 1 addition & 1 deletion docs/.vuepress/clientAppEnhance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Modal from '@/Modal.vue'
import Example1 from './components/Example1.vue'
import Intro from './components/Intro.vue'
import Modal from '@/Modal.vue'
import './styles/styles.scss'

import { defineClientAppEnhance } from '@vuepress/client'
Expand Down
2 changes: 1 addition & 1 deletion playground/layouts/default/Default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</template>

<script>
import DefaultNav from './DefaultNav.vue'
import DefaultFooter from './DefaultFooter.vue'
import DefaultNav from './DefaultNav.vue'
export default {
components: {
Expand Down
7 changes: 4 additions & 3 deletions playground/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import App from './App.vue'
import Default from './layouts/default/Default.vue'
import Modal from '@/Modal.vue'
import { createApp } from 'vue'
import { router } from './router'
import { store } from './store'
import Default from './layouts/default/Default.vue'
import App from './App.vue'
import Modal from '@/Modal.vue'

const app = createApp(App)

app.component('LayoutDefault', Default)
app.component('Modal', Modal)

Expand Down
2 changes: 1 addition & 1 deletion playground/router/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import Example1 from '../views/Example1.vue'
import { createRouter, createWebHashHistory } from 'vue-router'

const history = createWebHashHistory()
const routes = [
Expand Down
1 change: 1 addition & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
content: ['./**/*.html', './src/**/*.vue'],
defaultExtractor(content) {
const contentWithoutStyleBlocks = content.replace(/<style[^]+?<\/style>/gi, '')

return contentWithoutStyleBlocks.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || []
},
whitelist: [],
Expand Down
7 changes: 7 additions & 0 deletions src/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default {
const all = [].slice.call(this.$refs['vm-wrapper'].querySelectorAll(FOCUSABLE_ELEMENTS)).filter(function (el) {
return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length)
})
if (e.shiftKey) {
if (e.target === all[0] || e.target === this.$refs['vm-wrapper']) {
e.preventDefault()
Expand All @@ -192,17 +193,20 @@ export default {
},
handleFocus(wrapper) {
const autofocus = wrapper.querySelector('[autofocus]')
if (autofocus) {
autofocus.focus()
} else {
const focusable = wrapper.querySelectorAll(FOCUSABLE_ELEMENTS)
focusable.length ? focusable[0].focus() : wrapper.focus()
}
},
beforeOpen() {
// console.log('beforeOpen');
this.elToFocus = document.activeElement
const lastZindex = this.getTopZindex()
if (animatingZIndex) {
this.zIndex = animatingZIndex + 2
} else {
Expand Down Expand Up @@ -237,10 +241,13 @@ export default {
this.$nextTick(() => {
window.requestAnimationFrame(() => {
const lastZindex = this.getTopZindex()
if (lastZindex > 0) {
const all = this.getAllVisibleWrappers()
for (let i = 0; i < all.length; i++) {
const wrapper = all[i]
if (parseInt(wrapper.style.zIndex) === lastZindex) {
if (wrapper.contains(this.elToFocus)) {
this.elToFocus.focus()
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/ModalBasic.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Modal from '@/Modal.vue'
import { mount } from '@vue/test-utils'
import { waitRAF } from '../utils'
import Modal from '@/Modal.vue'

const createWrapperContainer = (componentArgs) => {
const args = componentArgs || {}

args.appendTo = '#modal-host'
const wrapperContainer = {
components: {
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('Modal basic functionality', () => {

it('hides the modal', async () => {
const wrapper = createWrapperContainer()

await wrapper.setData({ modelValue: true })
await wrapper.setData({ modelValue: false })

Expand Down
6 changes: 4 additions & 2 deletions tests/unit/ModalEvents.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils'
import { waitRAF, sleep } from '../utils'
import Modal from '@/Modal.vue'
import { mount } from '@vue/test-utils'
import { sleep, waitRAF } from '../utils'

const createWrapper = () => {
return mount(Modal, {
Expand All @@ -23,6 +23,7 @@ describe('Modal events', () => {

it.each(['before-open', 'opening', 'after-open'])('emits a %s event when opening', async (eventName) => {
const wrapper = createWrapper()

await wrapper.setProps({ modelValue: true })
await waitRAF()
await sleep(200)
Expand All @@ -32,6 +33,7 @@ describe('Modal events', () => {

it.each(['before-close', 'closing', 'after-close'])('emits a %s event when closing', async (eventName) => {
const wrapper = createWrapper()

await wrapper.setProps({ modelValue: true })
await waitRAF()
await wrapper.setProps({ modelValue: false })
Expand Down
24 changes: 22 additions & 2 deletions tests/unit/ModalFeatures.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils'
import { waitNT, sleep } from '../utils'
import Modal from '@/Modal.vue'
import { mount } from '@vue/test-utils'
import { sleep, waitNT } from '../utils'

const originalOffsetHeight = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetHeight')
const originalOffsetWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetWidth')
Expand Down Expand Up @@ -61,6 +61,7 @@ const createModalsWrapper = (data) => {

beforeAll(() => {
const style = document.createElement('style')

style.innerHTML = `
.vm-fadeIn, .vm-fadeOut {
animation-duration: 1ms;
Expand All @@ -72,6 +73,7 @@ beforeAll(() => {
describe('Modal features', () => {
beforeEach(() => {
const el = document.createElement('div')

el.id = 'modal-host'
document.body.appendChild(el)
})
Expand Down Expand Up @@ -111,6 +113,7 @@ describe('Modal features', () => {
await sleep(100)

const textInput = wrapper.getComponent('.modal-1').find('.modal-1 .text-input')

expect(document.activeElement).toEqual(textInput.element)
wrapper.unmount()
})
Expand All @@ -123,16 +126,19 @@ describe('Modal features', () => {
await sleep(300)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.find('button.open-modal-2').trigger('click')

await sleep(300)

const modal2 = wrapper.getComponent('.modal-2')

await modal2.find('.modal-2 button.vm-btn-close').trigger('click')

await sleep(300)

const textInput = modal1.find('.modal-1 .text-input')

expect(document.activeElement).toEqual(textInput.element)
wrapper.unmount()
})
Expand All @@ -145,18 +151,21 @@ describe('Modal features', () => {
await sleep(100)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.find('button.open-modal-2').trigger('click')

await sleep(100)

wrapper.setProps({ showInput: false })

const modal2 = wrapper.getComponent('.modal-2')

await modal2.find('.modal-2 button.vm-btn-close').trigger('click')

await sleep(100)

const closeBtn = modal1.find('.modal-1 button.vm-btn-close')

expect(document.activeElement).toEqual(closeBtn.element)
wrapper.unmount()
})
Expand All @@ -169,9 +178,11 @@ describe('Modal features', () => {
await sleep(100)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.trigger('keydown', { keyCode: 9 })

const textInput = modal1.find('.modal-1 .text-input')

expect(document.activeElement).toBe(textInput.element)
wrapper.unmount()
})
Expand All @@ -184,12 +195,14 @@ describe('Modal features', () => {
await sleep(100)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.trigger('keydown', {
keyCode: 9,
shiftKey: true
})

const checkboxInput = modal1.find('.modal-1 .checkbox-input')

expect(document.activeElement).toBe(checkboxInput.element)
wrapper.unmount()
})
Expand All @@ -202,6 +215,7 @@ describe('Modal features', () => {
await sleep(100)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.trigger('keydown', { keyCode: 27 })

await sleep(100)
Expand All @@ -218,6 +232,7 @@ describe('Modal features', () => {
await sleep(100)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.trigger('click')

await sleep(100)
Expand All @@ -239,6 +254,7 @@ describe('Modal features', () => {

const modal1 = wrapper.getComponent('.modal-1')
const modal1Backdrop = wrapper.getComponent('.vm-backdrop')

await modal1.find('.vm-btn-close').trigger('click')

await sleep(100)
Expand All @@ -259,9 +275,11 @@ describe('Modal features', () => {
await sleep(100)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.find('.modal-1 .checkbox-input').trigger('keydown', { keyCode: 9 })

const closeBtn = modal1.find('.modal-1 button.vm-btn-close')

expect(document.activeElement).toEqual(closeBtn.element)
wrapper.unmount()
})
Expand All @@ -274,6 +292,7 @@ describe('Modal features', () => {
await sleep(100)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.find('.modal-1 button.vm-btn-close').trigger('click')

await sleep(100)
Expand All @@ -290,6 +309,7 @@ describe('Modal features', () => {
await sleep(100)

const modal1 = wrapper.getComponent('.modal-1')

await modal1.find('button.open-modal-2').trigger('click')

await sleep(100)
Expand Down
2 changes: 2 additions & 0 deletions tests/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const createContainer = (tag = 'div') => {
const container = document.createElement(tag)

document.body.appendChild(container)

return container
}

Expand Down
3 changes: 2 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { minifyHtml, injectHtml } from 'vite-plugin-html'
import vue from '@vitejs/plugin-vue'
import { injectHtml, minifyHtml } from 'vite-plugin-html'
const path = require('path')
const { defineConfig } = require('vite')

Expand Down Expand Up @@ -48,6 +48,7 @@ module.exports = defineConfig({
if (assetInfo.name === 'style.css') {
return 'vue-modal.css'
}

return assetInfo.name
}
}
Expand Down

0 comments on commit b7abcb7

Please sign in to comment.