Skip to content

feat: support RefObject for useScrollSpy scrollHost#9066

Open
deshna1810 wants to merge 1 commit into
mantinedev:masterfrom
deshna1810:master
Open

feat: support RefObject for useScrollSpy scrollHost#9066
deshna1810 wants to merge 1 commit into
mantinedev:masterfrom
deshna1810:master

Conversation

@deshna1810

Copy link
Copy Markdown

Summary

This PR adds support for passing a React RefObject as the scrollHost option to useScrollSpy, in addition to the existing HTMLElement support.

Changes

  • Extended the scrollHost type to accept HTMLElement | RefObject<HTMLElement | null>.
  • Resolved the underlying DOM element internally when a ref is provided.
  • Preserved the existing behavior for HTMLElement inputs, ensuring full backward compatibility.
  • Updated the hook implementation to work seamlessly with React refs.
  • Added/updated tests to cover both HTMLElement and RefObject usage.

Motivation

Previously, scrollHost only accepted a resolved HTMLElement, which made using React refs awkward because ref.current is null during the initial render and doesn't trigger a re-render when populated. Supporting RefObject provides a more idiomatic React API and removes the need for callback ref or state-based workarounds while maintaining existing functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant