Skip to content

Commit

Permalink
Merge pull request jquense#2056 from Rdbaker/master
Browse files Browse the repository at this point in the history
Fixes the isSelected function to work if the value is equal
  • Loading branch information
pietrofxq authored Dec 2, 2021
2 parents 76e6254 + 5408236 commit 6ec4c93
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/selection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import isEqual from 'lodash/isEqual'

export function isSelected(event, selected) {
if (!event || selected == null) return false
return [].concat(selected).indexOf(event) !== -1
return isEqual(event, selected)
}

export function slotWidth(rowBox, slots) {
Expand All @@ -18,7 +20,7 @@ export function getSlotAtX(rowBox, x, rtl, slots) {
}

export function pointInBox(box, { x, y }) {
return y >= box.top && y <= box.bottom && (x >= box.left && x <= box.right)
return y >= box.top && y <= box.bottom && x >= box.left && x <= box.right
}

export function dateCellSelection(start, rowBox, box, slots, rtl) {
Expand Down
38 changes: 38 additions & 0 deletions test/utils/selection.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { isSelected } from '../../src/utils/selection'

describe('isSelected', () => {
test('it returns true if it is the same object by reference', () => {
const value = {
x: { sample: 'value' },
y: 1,
}
expect(isSelected(value, value)).toBeTruthy()
})

test('it returns true if it is the same object by equality', () => {
const value = {
x: { sample: 'value' },
y: 1,
}

const equalivalentValue = {
x: { sample: 'value' },
y: 1,
}
expect(isSelected(value, equalivalentValue)).toBeTruthy()
})

test('it returns false if the object is not equal', () => {
const value = {
x: { sample: 'value' },
y: 1,
}

const nonEqualivalentValue = {
x: { sample: 'value' },
y: 2,
}

expect(isSelected(value, nonEqualivalentValue)).toBeFalsy()
})
})

0 comments on commit 6ec4c93

Please sign in to comment.