Skip to content

Commit 77d4115

Browse files
authored
fix: do not swallow dom props (#23)
* fix: do not swallow dom props * memoize reposition callback
1 parent 232705a commit 77d4115

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/Stick.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function Stick({
4242
autoFlipHorizontally,
4343
autoFlipVertically,
4444
onClickOutside,
45+
...rest
4546
}: PropsT) {
4647
const [width, setWidth] = useState(0)
4748
const [containerNestingKeyExtension] = useState(() => uniqueId())
@@ -125,14 +126,27 @@ function Stick({
125126
getModifiers({ position: resolvedPosition, align: resolvedAlign })
126127
)
127128

129+
const handleReposition = useCallback(() => {
130+
if (nodeRef.current && anchorRef.current) {
131+
checkAlignment(nodeRef.current, anchorRef.current)
132+
}
133+
}, [checkAlignment])
134+
128135
if (!node) {
129-
return children
136+
const Component = component || 'div'
137+
138+
return (
139+
<StickContext.Provider value={nestingKey}>
140+
<Component {...rest}>{children}</Component>
141+
</StickContext.Provider>
142+
)
130143
}
131144

132145
if (inline) {
133146
return (
134147
<StickContext.Provider value={nestingKey}>
135148
<StickInline
149+
{...rest}
136150
position={resolvedPosition}
137151
align={resolvedAlign}
138152
node={
@@ -162,6 +176,7 @@ function Stick({
162176
return (
163177
<StickContext.Provider value={nestingKey}>
164178
<StickPortal
179+
{...rest}
165180
updateOnAnimationFrame={!!updateOnAnimationFrame}
166181
transportTo={transportTo}
167182
component={component}
@@ -188,11 +203,7 @@ function Stick({
188203
style={resolvedStyle}
189204
nestingKey={nestingKey}
190205
containerRef={containerRef}
191-
onReposition={() => {
192-
if (nodeRef.current && anchorRef.current) {
193-
checkAlignment(nodeRef.current, anchorRef.current)
194-
}
195-
}}
206+
onReposition={handleReposition}
196207
>
197208
{children}
198209
</StickPortal>

src/StickInline.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ function StickInline({
1919
component,
2020
containerRef,
2121
nestingKey,
22+
...rest
2223
}: PropsT) {
2324
const Component = component || 'div'
2425
return (
25-
<Component {...style} ref={containerRef} data-sticknestingkey={nestingKey}>
26+
<Component
27+
{...style}
28+
{...rest}
29+
ref={containerRef}
30+
data-sticknestingkey={nestingKey}
31+
>
2632
{children}
2733
{node && <div {...style('node')}>{node}</div>}
2834
</Component>

src/StickPortal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function StickPortal(
7777
return (
7878
<Component
7979
{...style}
80+
{...rest}
8081
ref={node => {
8182
if (typeof ref === 'function') {
8283
ref(node)

0 commit comments

Comments
 (0)