Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
Move element to viewport when is active

I have a horizontal menu with buttons, on mobile you can drag and move left or right to see all elements. When you click on the button it becomes the 'active' button, I add some styling. What I would achieve here is that when some clicks on a button, it will automatically move to the left or right and become fully visible.

buttons

as you can see button on the right side is active but it is out of the viewport

I'm looking for ideas on how I could implement such a mechanism in React/Typescript with Emotion

this is a wrapper/container of buttons:

const StyledDiv = withTheme(
  styled.div<StyledProps>`
    display: flex;
    flex-wrap: nowrap;
    overflow: auto
    width: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
    column-gap: 8px;
    -webkit-overflow-scrolling: touch;
    &::-webkit-scrollbar {
      display: none;
   }
  `
)

this is how button is built itself

  return (
    <Button data-label={label} isActive={isActive} onClick={() => setActiveCategory(cat)}>
      { renderIcon(icon) }
      <Wrapper>
        {label}
        <StyledSpan isActive={isActive}>{label}</StyledSpan>
      </Wrapper>
    </Button>
  )

and here are CSS code for button

const Button = withTheme(
  styled.button<ActiveButtonProps>`
    padding: 4px 16px 4px 8px;
    font-family: ${({ theme }) => theme.fontFamily.sora};
    border-radius: 4px;
    font-size: 12px;
    line-height: 15px;
    color: ${({ theme }) => theme.horizontalBar.color};
    box-shadow: 0px 2px 4px ${({ theme }) => theme.horizontalBar.boxShadow};
    outline: none;
    background-color: ${({ theme }) => theme.horizontalBar.bgColor};
    border: 1px solid transparent;
    height: 52px;
    display: inline-flex;
    align-items: center;
    position: relative;
    white-space: nowrap;
    cursor: pointer;
    transition: all .3s;
    font-weight: 400;
    border: ${ props => props.isActive ? `1px solid ${color.primary.powerGreen}` : `1px solid transparent`};
    & > img {
      margin-right: 4px; 
    }
  `
)

const StyledSpan = withTheme(
  styled.span<ActiveButtonProps>`
    font-weight: ${ props => props.isActive ? 700 : 400 };
    color: ${ props => props.isActive ? ({ theme }) => theme.horizontalBar.color : ({ theme }) => theme.horizontalBar.colorInactive };
    position: absolute;
    left: 0;
  `
)

const Wrapper = withTheme(
  styled.p<StyledProps>`
    margin: 0;
    position: relative;
    color: transparent;
  `
)
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda