Skip to content

Commit 1cf27a0

Browse files
committed
hold title before release
1 parent 7a8cea5 commit 1cf27a0

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

app/components/button.jsx

+12-10
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,28 @@ function Button(props) {
4343
}
4444

4545
useEffect(() => {
46-
return () => {
47-
if (timeRef.current) {
48-
clearTimeout(timeRef.current);
49-
}
50-
};
51-
}, []);
46+
if (isPortalOpen) {
47+
const displayTime = Math.min(8, 0.1 * title.length) * 1000;
48+
const timeout = setTimeout(() => {
49+
setIsPortalOpen(false);
50+
}, displayTime);
51+
return () => clearTimeout(timeout);
52+
}
53+
}, [isPortalOpen, title.length]);
5254

5355

5456
return (
55-
<div
57+
<span
5658
onMouseDown={handleMouseDown}
5759
onMouseUp={handleMouseUp}
5860
onMouseLeave={handleMouseUp}
5961
>
6062
<PositioningPortal
6163
isOpen={isPortalOpen}
6264
portalContent={
63-
<div>
65+
<span>
6466
{title}
65-
</div>
67+
</span>
6668
}>
6769
<button
6870
className={combinedClassName}
@@ -78,7 +80,7 @@ function Button(props) {
7880
</button>
7981
</PositioningPortal>
8082

81-
</div>
83+
</span>
8284

8385
)
8486
}

stories/button.stories.jsx

+9
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,13 @@ HoverTest.args = {
6363
disabled: false,
6464
disableOnClick: false,
6565
children: "Hover State Button"
66+
};
67+
68+
export const LongPressTest = Template(SecondaryButton).bind({});
69+
LongPressTest.args = {
70+
onDone: null,
71+
title: "Press me fdsaf fdasfds ewfavdszvwea dafd adfgew vdfgreat fsdgaew",
72+
disabled: false,
73+
disableOnClick: false,
74+
children: "Hover State Button"
6675
};

0 commit comments

Comments
 (0)