Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cutterbl committed Dec 8, 2021
2 parents c75ad1a + 6ec4c93 commit 7a5f5d6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export default class TimeGrid extends Component {
const { min, max, scrollToTime, localizer } = props

const diffMillis = scrollToTime - localizer.startOf(scrollToTime, 'day')
const totalMillis = localizer.diff(max, min)
const totalMillis = localizer.diff(min, max, 'milliseconds')

this._scrollRatio = diffMillis / totalMillis
}
Expand Down
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 7a5f5d6

Please sign in to comment.