useScrollToBlock
Returns a function that scrolls the viewport to a block, such as jumping to a search hit or a form field.
const scrollToBlock = useScrollToBlock()
scrollToBlock(blockId, options?)blockIdis a block id from the SDK, such as a widget id from useWidgets. An unknown or deleted id throwsInvalidInputError; with no document loaded, the call throwsDocumentNotLoadedError.optionsare the same alignment options as in useScrollToPage, applied to the block's bounds instead of the page.
Example
import { useScrollToBlock, useWidgets } from '@sdk-pdf/react'
function useScrollToFirstEmptyField() {
const { widgets } = useWidgets()
const scrollToBlock = useScrollToBlock()
return (fieldName: string) => {
const widget = widgets.find((widget) => widget.fieldName === fieldName)
if (widget) scrollToBlock(widget.id, { behavior: 'smooth', vertical: 'center' })
}
}