-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(event): support FocusEvents in localPoint (#956)
- Loading branch information
1 parent
aa1dcae
commit 9861417
Showing
4 changed files
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export type EventType = MouseEvent | TouchEvent | React.MouseEvent | React.TouchEvent; | ||
export type EventType = | ||
| MouseEvent | ||
| TouchEvent | ||
| FocusEvent | ||
| React.MouseEvent | ||
| React.TouchEvent | ||
| React.FocusEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
import getXAndYFromEvent from '../src/getXAndYFromEvent'; | ||
|
||
describe('getXAndYFromEvent()', () => { | ||
test('it should return { x: 0, y: 0 } if no event argument', () => { | ||
it('should return { x: 0, y: 0 } if no event argument', () => { | ||
const result = getXAndYFromEvent(); | ||
// @ts-ignore | ||
const result2 = getXAndYFromEvent(null); | ||
expect(result).toEqual({ x: 0, y: 0 }); | ||
expect(result2).toEqual({ x: 0, y: 0 }); | ||
}); | ||
|
||
test('it should return { x, y } for mouse events', () => { | ||
it('should return { x, y } for mouse events', () => { | ||
const e = { clientX: 0, clientY: 0 }; | ||
const result = getXAndYFromEvent(e as MouseEvent); | ||
expect(result).toEqual({ x: e.clientX, y: e.clientY }); | ||
}); | ||
|
||
test('it should return { x, y } for touch events with changedTouches', () => { | ||
it('should return { x, y } for touch events with changedTouches', () => { | ||
const touch0 = { clientX: 0, clientY: 0 }; | ||
const touch1 = { clientX: 1, clientY: 1 }; | ||
const e = { changedTouches: [touch0, touch1] }; | ||
const result = getXAndYFromEvent((e as unknown) as TouchEvent); | ||
expect(result).toEqual({ x: touch0.clientX, y: touch0.clientY }); | ||
}); | ||
|
||
test('it should return { x: 0, y: 0 } for touch events with no changedTouches', () => { | ||
it('should return { x: 0, y: 0 } for touch events with no changedTouches', () => { | ||
const e = { changedTouches: [] }; | ||
const result = getXAndYFromEvent((e as unknown) as TouchEvent); | ||
expect(result).toEqual({ x: 0, y: 0 }); | ||
}); | ||
|
||
it('should return the middle of an element for focus events', () => { | ||
const e = { target: { getBoundingClientRect: () => ({ x: 5, y: 5, width: 10, height: 2 }) } }; | ||
const result = getXAndYFromEvent((e as unknown) as FocusEvent); | ||
expect(result).toEqual({ x: 10, y: 6 }); | ||
}); | ||
}); |