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

112
Visualizações
Make scrollIntoView() only scroll the dropdown list, not entire page

Am using React and formik , I want to scroll items in the list but it scrolls to the certain item, but the only challenge is that , it also crolls the entire page, I dont want the entire page to be scrolled, how can I solve this:

NOTE:

I always want Germany as a country to be at the top, this works , but it also scrolls the entire page, which I don't want

Below is my code :

const getOptionRender = {
    internationalPrefix: (option: CountryType) => (
        <Typography data-name={option.country}>
            {option.country} +{option.prefix}
        </Typography>
    ),
    nationality: (option: CountryType) => (
        <Typography data-name={option.nationality}>{option.countryNationality}</Typography>
    ),
    country: (option: CountryType) => (
        <Typography data-name={option.country}>{option.country} ===</Typography>
    ),
};


   const handleOnOpenCountryList = useCallback(() => {
        const getOptionScroller = {
            internationalPrefix: '49',
            nationality: 'Deutsch',
            country: 'Deutschland',
        };
        setTimeout(() => {
            const optionEl = document.querySelector(`[data-name="${getOptionScroller[type]}"]`);
            optionEl?.scrollIntoView({
                behavior: 'smooth', block: 'center', inline: "center"
            });
        }, 1);
    }, [type]);


return (
        <FastField
            name={name}
            onOpen={handleOnOpenCountryList}
            component={CustomAutocomplete}
            options={sortedCountryList}
            getOptionLabel={handleGetOptionLabel}
            getOptionSelected={handleGetOptionSelected}
            disableClearable
            renderOption={handleGetOptionRender}
            renderInput={handleRenderInput}
            size="small"
            shouldUpdate={shouldFastFieldUpdate}
            {...props}
        />
    );

If you look closely, the way I scroll is done by this code :

setTimeout(() => {
            const optionEl = document.querySelector(`[data-name="${getOptionScroller[type]}"]`);
            optionEl?.scrollIntoView({
                behavior: 'smooth', block: 'center', inline: "center"
            });
        }, 1);

What went wrong ?

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