Skip to content

Commit

Permalink
fix(slider): boundary slider enhancement (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraTschamon authored Sep 12, 2024
1 parent d126c1a commit 2fd7bc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/Slider/Slider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('The Slider component', () => {
it('displays a boundary slider', () => {
setup({ variant: 'boundary' });

expect(screen.getAllByRole('slider')).toHaveLength(3);
expect(screen.getByRole('slider')).toBeInTheDocument();
});

it('displays the correct boundary slider min and max texts', () => {
Expand Down
28 changes: 17 additions & 11 deletions src/components/Slider/Slider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleProps, useMediaQuery } from '@chakra-ui/react';
import { Box, StyleProps, useMediaQuery } from '@chakra-ui/react';
import React, { useEffect, useMemo, useState } from 'react';
import {
Slider,
Expand Down Expand Up @@ -48,6 +48,8 @@ export const BoemlySlider: React.FC<SliderProps> = ({
const [sliderValue, setSliderValue] = useState(initialValue);
const [inputValue, setInputValue] = useState(initialValue.toString());

const sliderHeight = 4;

// Update internal sliderValue when the external value prop changes
useEffect(() => {
if (value !== undefined) {
Expand Down Expand Up @@ -84,11 +86,13 @@ export const BoemlySlider: React.FC<SliderProps> = ({
mt="8"
>
<Flex flexDir="row" alignItems="center" justifyContent="center" width="full">
<Slider role="slider" width="10%" mr={2} cursor="default">
<SliderTrack backgroundColor="gray.200">
<SliderFilledTrack backgroundColor="gray.200" />
</SliderTrack>
</Slider>
<Box
height={`${sliderHeight}px`}
width="10%"
mr={2}
backgroundColor="gray.200"
borderRadius="full"
/>

<Slider
aria-label={ariaLabel}
Expand All @@ -106,11 +110,13 @@ export const BoemlySlider: React.FC<SliderProps> = ({
<CustomSliderThumb sliderValue={sliderValue} unit={unit} showTooltip={true} />
</Slider>

<Slider role="slider" width="10%" ml={2} cursor="default">
<SliderTrack backgroundColor="gray.200">
<SliderFilledTrack backgroundColor="gray.200" />
</SliderTrack>
</Slider>
<Box
height={`${sliderHeight}px`}
width="10%"
ml={2}
backgroundColor="gray.200"
borderRadius="full"
/>
</Flex>

<Flex flexDir="row" width="full" justifyContent="space-between">
Expand Down

0 comments on commit 2fd7bc8

Please sign in to comment.