# useFocusedWidgetId

Source: https://sdk.pdf.net/docs/v1/reference/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.

```ts
const focusedWidgetId = useFocusedWidgetId() // string | undefined
```

* The focused widget is not a selected block, so it doesn't appear in [useSelectedBlocks](https://sdk.pdf.net/docs/v1/reference/useSelectedBlocks) or [useSelection](https://sdk.pdf.net/docs/v1/reference/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 [#example]

```tsx
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](https://sdk.pdf.net/docs/v1/guides/working-with-forms) for form filling.

