Skip to content

feat(new props deactivationSelector): deactivation only in deactivati… #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v2
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
9 changes: 9 additions & 0 deletions src/components/vue-draggable-resizable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export default {
type: Boolean,
default: false
},
deactivationSelector: {
type: String,
default: null
},
active: {
type: Boolean,
default: false
Expand Down Expand Up @@ -423,6 +427,11 @@ export default {
const target = e.target || e.srcElement
const regex = new RegExp(this.className + '-([trmbl]{2})', '')

if (this.deactivationSelector && document.querySelector(this.deactivationSelector) && !document.querySelector(this.deactivationSelector).contains(target)) {
this.resetBoundsAndMouseState()
return
}

if (!this.$el.contains(target) && !regex.test(target.className)) {
if (this.enabled && !this.preventDeactivation) {
this.enabled = false
Expand Down
26 changes: 26 additions & 0 deletions tests/feature/specs/props/active.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,29 @@ describe('`prevent-deactivation` prop', function () {

afterEach(() => wrapper.destroy())
})

describe('`deactivation-selector` prop', function () {
it('should not deactivate the component when clicking outside the deactivationSelector ', function (done) {
wrapper = mount(VueDraggableResizable, {
attachToDocument: true,
propsData: {
active: true,
preventDeactivation: false,
deactivationSelector: 'body'
}
})

expect(wrapper.props().active).to.be.true

syn.click(document.documentElement)

wrapper.vm.$nextTick(() => {
expect(wrapper.props().active).to.be.true
expect(wrapper.emitted()).to.not.have.property('deactivated')

done()
})
})

afterEach(() => wrapper.destroy())
})