Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keeping Focus in Place with Load-More Buttons #125

Open
AleksandrHovhannisyan opened this issue Dec 9, 2021 · 3 comments
Open

Keeping Focus in Place with Load-More Buttons #125

AleksandrHovhannisyan opened this issue Dec 9, 2021 · 3 comments
Labels
comments Comments section for an article.

Comments

@AleksandrHovhannisyan
Copy link
Owner

No description provided.

@AleksandrHovhannisyan AleksandrHovhannisyan added the comments Comments section for an article. label Dec 9, 2021
@EllyLoel
Copy link

Awesome post! Thanks for sharing 😄

@jkettmann
Copy link

Great blog post. Helped a lot. Only one suggestion: You can simplify the code a bit by using a ref callback. That way you don't need the useEffect either 😄

const ResultGrid = (props) => {
  const onMount = (ref) => {
    if (ref) {
      ref.focus();
    }
  }

  return (
    <>
      <ol>
        {props.results.map((result, i) => {
          const isFirstNewResult = i === props.firstNewResultIndex;
          return (
            <li key={i} id={`result-${i}`}>
              <a
                ref={isFirstNewResult ? onMount : undefined}

@AleksandrHovhannisyan
Copy link
Owner Author

@jkettmann Clever, thanks for sharing! I'll see if I can get around to updating the article with that approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comments Comments section for an article.
Projects
None yet
Development

No branches or pull requests

3 participants