14

I'm working with Chakra UI and i needed to customize the scrollbar style using the css pseudo element ::-webkit-scrollbar, but Chakra UI doesn't seen to have this pseudo element and a I don't know where I can style this specific component without creating a global css class.

Here is a sample of my code:

<Box
  overflowX="auto"
  maxW="100vw"
  h="100%"
  whiteSpace="nowrap"
  pb="17px"
  color="white"
  px="32px"
  // the ::-webkit-scrollbar property should goes here
>
  <!-- content -->
</Box>
Gabriel Mochi
  • 509
  • 1
  • 4
  • 10

4 Answers4

31

Try css prop:

<Box
  overflowY="auto"
  css={{
    '&::-webkit-scrollbar': {
      width: '4px',
    },
    '&::-webkit-scrollbar-track': {
      width: '6px',
    },
    '&::-webkit-scrollbar-thumb': {
      background: scrollbarColor,
      borderRadius: '24px',
    },
  }}
>
nbsp
  • 378
  • 3
  • 9
4

Use Chakra sx prop here.

<Box
  overflowX="auto"
  maxW="100vw"
  h="100%"
  whiteSpace="nowrap"
  pb="17px"
  color="white"
  px="32px"
  sx={
     { 
    '::-webkit-scrollbar':{
           display:'none'
       }
    }
  }
>
  <!-- content -->
</Box>

To know more about Chakra sx prop, refer docs

Abir
  • 170
  • 2
  • 5
2

It worked for me you can use overflow="scroll" and with this the prop sx={}

<Flex
    mt="20px"
    overflow="scroll"
    sx={{
      "::-webkit-scrollbar": {
        display: "none",
      },
    }}
  />
Ateeb Asif
  • 94
  • 3
1

its not gonna work with just css you need to __css

<Box
  overflowY="auto"
  __css={{
        '&::-webkit-scrollbar': {
          w: '2',
        },
        '&::-webkit-scrollbar-track': {
          w: '6',
        },
        '&::-webkit-scrollbar-thumb': {
          borderRadius: '10',
          bg: `gray.100`,
        },
      }}
>
malek
  • 9
  • 2