Skip to content
Closed
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"size-limit": [
{
"limit": "1.875 KB",
"limit": "1.891 KB",
"path": "es/index.js"
}
],
Expand Down
26 changes: 24 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ export function useSwipeable(props) {
return handlers
}

const reservedProps = {
delta: true,
innerRef: true,
nodeName: true,
onSwiped: true,
onSwipedDown: true,
onSwipedLeft: true,
onSwipedRight: true,
onSwipedUp: true,
onSwiping: true,
preventDefaultTouchmoveEvent: true,
rotationAngle: true,
trackMouse: true,
trackTouch: true
}

export class Swipeable extends React.PureComponent {
static propTypes = {
onSwiped: PropTypes.func,
Expand Down Expand Up @@ -248,10 +264,16 @@ export class Swipeable extends React.PureComponent {
}

render() {
const { className, style, nodeName = 'div', innerRef, children, trackMouse } = this.props
const { nodeName = 'div', innerRef, children, trackMouse } = this.props
const otherProps = {}
for (const prop in this.props) {
if (!reservedProps[prop]) {
otherProps[prop] = this.props[prop]
}
}
const [handlers, attachTouch] = getHandlers(this._set, { trackMouse })
this.transientState = updateTransientState(this.transientState, this.props, attachTouch)
const ref = innerRef ? el => (innerRef(el), handlers.ref(el)) : handlers.ref
return React.createElement(nodeName, { ...handlers, className, style, ref }, children)
return React.createElement(nodeName, { ...otherProps, ...handlers, ref }, children)
}
}
4 changes: 1 addition & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ export interface SwipeableOptions {
}

// Component Specific Props
export interface SwipeableProps {
export interface SwipeableProps extends React.HTMLProps<HTMLDivElement> {
nodeName?: string
innerRef?: (element: HTMLElement | null) => void
children?: React.ReactNode
style?: React.CSSProperties
className?: string
}

export interface SwipeableHandlers {
Expand Down
1 change: 1 addition & 0 deletions types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SampleComponent extends React.PureComponent<SwipeableProps> {
innerRef={() => {}}
style={{ backgroundColor: 'blue' }}
className="classname"
aria-hidden={false}
>
<div>This element can be swiped</div>
</Swipeable>
Expand Down