useFocusedWidgetId
Returns the id of the form widget whose control has the keyboard focus, which is how the user fills a widget in the interactive content policy, and re-renders the component when the focus moves. Returns undefined when no widget is focused.
const focusedWidgetId = useFocusedWidgetId() // string | undefined- The focused widget is not a selected block, so it doesn't appear in useSelectedBlocks or useSelection.
- A read-only widget counts when its control takes the focus: a read-only text field does, a read-only check box doesn't.
- When the focus moves straight from one widget to another, the value changes from the first id to the second; the moment in between isn't observable.
- The id is session-scoped: don't store it across page reloads.
Example
import { useFocusedWidgetId, useWidgetById } from '@sdk-pdf/react'
function FieldHint() {
const focusedWidgetId = useFocusedWidgetId()
const widget = useWidgetById(focusedWidgetId ?? '')
if (!widget) return null
return <div role="status">Filling {widget.fieldName}</div>
}See Working with forms for form filling.