Skip to content

Commit 4ca40a1

Browse files
removed absolute positioning
1 parent ed28aa5 commit 4ca40a1

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

src/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ function ToggleSlider({
8282
}
8383

8484
const overlayStyles: CSSProperties = {
85+
boxSizing: "border-box",
8586
width: "100%",
86-
height: "100%",
87-
position: "absolute",
88-
transition: `all ${transitionDuration}`,
87+
flex: "none",
8988
};
9089

9190
barStyles = active ? { ...barStyles, ...barStylesActive } : barStyles;
@@ -108,16 +107,19 @@ function ToggleSlider({
108107
const handleActive = handleRendererActive ?? handle;
109108

110109
return (
111-
<div style={{ position: "relative", cursor: "pointer" }} onClick={onClick}>
112-
<div style={{ top: Math.max(handleSize - barHeight, 0) / 2, left: 0, ...overlayStyles }}>
110+
<div style={{ display: "flex", flexFlow: "row nowrap", cursor: "pointer", width: barWidth }} onClick={onClick}>
111+
<div style={{ paddingTop: Math.max(handleSize - barHeight, 0) / 2 ,transition: `all ${transitionDuration}`, ...overlayStyles }}>
113112
{active ? barActive : bar}
114113
</div>
115-
<div style={{
116-
top: Math.max(barHeight - handleSize, 0) / 2,
117-
left: ((active && !flip || !active && flip) ? barWidth - padding - handleSize : padding),
118-
...overlayStyles
119-
}}>
120-
{active ? handleActive : handle}
114+
<div style={{ marginLeft: "-100%", ...overlayStyles }}>
115+
<div
116+
style={{
117+
transition: `all ${transitionDuration}`,
118+
paddingTop: Math.max(barHeight - handleSize, 0) / 2,
119+
paddingLeft: ((active && !flip || !active && flip) ? barWidth - padding - handleSize : padding),
120+
}}>
121+
{active ? handleActive : handle}
122+
</div>
121123
</div>
122124
</div>
123125
);
@@ -126,6 +128,7 @@ function ToggleSlider({
126128
export function useToggleSlider(props?: ToggleSliderProps) {
127129

128130
const [activeState, setActiveState] = useState(props?.active ?? false);
131+
129132
function onToggle(value: boolean) {
130133
setActiveState(value);
131134
}

0 commit comments

Comments
 (0)