Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!