Skip to content
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

bug(types): SwipeableHandlers.ref accepts null. #142

Merged
Merged
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
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"import",
"react"
]
}
}
4 changes: 2 additions & 2 deletions src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function setupGetMountedComponent(TYPE, mockListeners = mockListenersSetup) {
})
})

it('Cleans up and re-attachs touch event listeners', () => {
it('Cleans up and re-attaches touch event listeners', () => {
let spies
const mockListeners = el => {
// already spying
Expand Down Expand Up @@ -412,7 +412,7 @@ function setupGetMountedComponent(TYPE, mockListeners = mockListenersSetup) {
})
})

it(`${TYPE} hanldes updated prop swipe callbacks`, () => {
it(`${TYPE} handles updated prop swipe callbacks`, () => {
let eventListenerMap
const innerRef = el => {
// don't re-assign eventlistener map
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface EventData {
dir: 'Left' | 'Right' | 'Up' | 'Down'
}

export type SwipeCallback = ({}: EventData) => void
export type SwipeCallback = (eventData: EventData) => void

export interface SwipeableOptions {
// Event handler/callbacks
Expand All @@ -34,14 +34,14 @@ export interface SwipeableOptions {
// Component Specific Props
export interface SwipeableProps {
nodeName?: string
innerRef?: ({}: HTMLElement) => void
innerRef?: (element: HTMLElement | null) => void
children?: React.ReactNode
style?: React.CSSProperties
className?: string
}

export interface SwipeableHandlers {
ref: ({}: HTMLElement) => void
ref: (element: HTMLElement | null) => void
onMouseDown?: React.MouseEventHandler
}

Expand Down
15 changes: 13 additions & 2 deletions types/test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { Swipeable, SwipeableProps, SwipeCallback, useSwipeable } from 'react-swipeable'
import { Swipeable, SwipeableHandlers, SwipeableProps, SwipeCallback, useSwipeable } from 'react-swipeable'

class SampleComponent extends React.PureComponent<SwipeableProps> {
private readonly handleSwiped: SwipeCallback = () => {}
Expand Down Expand Up @@ -41,7 +41,7 @@ class SampleComponent extends React.PureComponent<SwipeableProps> {

class SwipeableDiv extends Swipeable {}

const TestComponent: React.StatelessComponent = _ => {
const TestComponent: React.FunctionComponent = _ => {
const handleSwiped: SwipeCallback = () => {}

return (
Expand All @@ -56,3 +56,14 @@ const TestHook = () => {
const handlers = useSwipeable({ onSwiped: ({ dir }) => setDir(dir) })
return <div {...handlers} >{swipeDir}</div>
}

const handlers: SwipeableHandlers = useSwipeable({
onSwipedLeft: (data) => {
data // $ExpectType EventData
},
preventDefaultTouchmoveEvent: true,
trackTouch: true,
})

handlers.ref(<div />)
handlers.ref(null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome tests! thank you!