Skip to content

Commit

Permalink
fix(slider): ✏️ fix focus on Slider and stories
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Aug 20, 2020
1 parent 3b6e4a4 commit 841a63e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
7 changes: 0 additions & 7 deletions src/slider/SliderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export function useSliderState(props: UseSliderProps = {}) {
} = props;

const [isDragging, setDragging] = useBoolean();
const [isFocused, setFocused] = useBoolean();

const [eventSource, setEventSource] = useState<EventSource>();

Expand Down Expand Up @@ -454,16 +453,12 @@ export function useSliderState(props: UseSliderProps = {}) {
rootRef.current,
);

const onFocus = useCallback(() => setFocused.on(), [setFocused]);
const onBlur = useCallback(() => setFocused.off(), [setFocused]);

return {
actions,
state: {
min,
max,
value,
isFocused,
isDragging,
isDisabled,
isReadOnly,
Expand All @@ -476,8 +471,6 @@ export function useSliderState(props: UseSliderProps = {}) {
},
handlers: {
onKeyDown,
onFocus,
onBlur,
},
styles: {
rootStyle,
Expand Down
2 changes: 0 additions & 2 deletions src/slider/SliderThumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ export const useSliderThumb = createHook<useSliderThumbOptions, BoxHTMLProps>({
"aria-disabled": ariaAttr(options.state.isDisabled),
"aria-readonly": ariaAttr(options.state.isReadOnly),
onKeyDown: callAllHandlers(htmlOnKeyDown, options.handlers.onKeyDown),
onFocus: callAllHandlers(htmlOnFocus, options.handlers.onFocus),
onBlur: callAllHandlers(htmlOnBlur, options.handlers.onBlur),
style: { ...options.styles.thumbStyle, ...htmlStyle },
...htmlProps,
};
Expand Down
58 changes: 49 additions & 9 deletions src/slider/stories/Slider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
} as Meta;

export const Default = () => {
const slider = useSliderState({ isDisabled: true });
const slider = useSliderState();

return (
<Slider {...slider} style={sliderHorizontalStyle}>
Expand All @@ -35,7 +35,12 @@ export const Default = () => {
<SliderThumb
{...slider}
aria-label="slider-thumb"
style={sliderHorizontalThumbStyle}
style={{
...sliderHorizontalThumbStyle,
transform: slider.state.isDragging
? "translateY(-50%) scale(1.15)"
: sliderHorizontalThumbStyle.transform,
}}
/>
</Slider>
);
Expand All @@ -55,7 +60,12 @@ export const Reversed = () => {
<SliderThumb
{...slider}
aria-label="slider-thumb"
style={sliderHorizontalThumbStyle}
style={{
...sliderHorizontalThumbStyle,
transform: slider.state.isDragging
? "translateY(-50%) scale(1.15)"
: sliderHorizontalThumbStyle.transform,
}}
/>
</Slider>
);
Expand All @@ -75,7 +85,12 @@ export const Min20Max80 = () => {
<SliderThumb
{...slider}
aria-label="slider-thumb"
style={sliderHorizontalThumbStyle}
style={{
...sliderHorizontalThumbStyle,
transform: slider.state.isDragging
? "translateY(-50%) scale(1.15)"
: sliderHorizontalThumbStyle.transform,
}}
/>
</Slider>
);
Expand All @@ -95,7 +110,12 @@ export const Step10 = () => {
<SliderThumb
{...slider}
aria-label="slider-thumb"
style={sliderHorizontalThumbStyle}
style={{
...sliderHorizontalThumbStyle,
transform: slider.state.isDragging
? "translateY(-50%) scale(1.15)"
: sliderHorizontalThumbStyle.transform,
}}
/>
</Slider>
);
Expand All @@ -115,7 +135,12 @@ export const DefaultValue90 = () => {
<SliderThumb
{...slider}
aria-label="slider-thumb"
style={sliderHorizontalThumbStyle}
style={{
...sliderHorizontalThumbStyle,
transform: slider.state.isDragging
? "translateY(-50%) scale(1.15)"
: sliderHorizontalThumbStyle.transform,
}}
/>
</Slider>
);
Expand All @@ -135,7 +160,12 @@ export const Disabled = () => {
<SliderThumb
{...slider}
aria-label="slider-thumb"
style={sliderHorizontalThumbStyle}
style={{
...sliderHorizontalThumbStyle,
transform: slider.state.isDragging
? "translateY(-50%) scale(1.15)"
: sliderHorizontalThumbStyle.transform,
}}
/>
</Slider>
);
Expand All @@ -155,7 +185,12 @@ export const ReadOnly = () => {
<SliderThumb
{...slider}
aria-label="slider-thumb"
style={sliderHorizontalThumbStyle}
style={{
...sliderHorizontalThumbStyle,
transform: slider.state.isDragging
? "translateY(-50%) scale(1.15)"
: sliderHorizontalThumbStyle.transform,
}}
/>
</Slider>
);
Expand All @@ -172,7 +207,12 @@ export const Vertical = () => {
<SliderThumb
{...slider}
aria-label="slider-thumb"
style={sliderVerticalThumbStyle}
style={{
...sliderVerticalThumbStyle,
transform: slider.state.isDragging
? "translateX(-50%) scale(1.15)"
: sliderVerticalThumbStyle.transform,
}}
/>
</Slider>
);
Expand Down
1 change: 0 additions & 1 deletion src/slider/stories/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const sliderThumbStyle: CSSProperties = {
"rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px",
width: "14px",
height: "14px",
outline: "0px",
borderRadius: "9999px",
background: "rgb(255, 255, 255)",
borderWidth: "1px",
Expand Down

0 comments on commit 841a63e

Please sign in to comment.