# @roqueform/ref-plugin

> Associates Roqueform fields with DOM elements.

Latest version **5.0.0** (published 2024-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @roqueform/ref-plugin
pnpm add @roqueform/ref-plugin
yarn add @roqueform/ref-plugin
bun add @roqueform/ref-plugin
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2024-01-30 |
| First published | 2022-08-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Savva Mikhalevski |
| Maintainers | smikhalevski |
| Keywords | roqueform, form, field, plugin, dom, ref |

## Links

- npm: https://www.npmjs.com/package/@roqueform/ref-plugin
- Repository: https://github.com/smikhalevski/roqueform
- Homepage: https://github.com/smikhalevski/roqueform/tree/master/packages/ref-plugin#readme
- Issues: https://github.com/smikhalevski/roqueform/issues
- npm.io page: https://npm.io/package/@roqueform/ref-plugin

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2024-01-30
- 4.0.1 — 2023-08-22
- 4.0.0 — 2023-03-21
- 3.0.0 — 2022-11-23
- 2.1.0 — 2022-08-12
- 2.0.0 — 2022-08-05

## README

# DOM reference plugin for Roqueform

Associates [Roqueform](https://github.com/smikhalevski/roqueform#readme) fields with DOM elements.

```sh
npm install --save-prod @roqueform/ref-plugin
```

# Overview

🔎 [API documentation is available here.](https://smikhalevski.github.io/roqueform/modules/_roqueform_ref_plugin.html)

This plugin doesn't require any rendering framework. To simplify the usage example, we're going to use
[the React integration](../react#readme).

```tsx
import { FieldRenderer, useField } from '@roqueform/react';
import { refPlugin } from '@roqueform/ref-plugin';

export const App = () => {
  const planetField = useField({ name: 'Venus' }, refPlugin());

  return (
    <FieldRenderer field={planetField.at('name')}>
      {nameField => (
        <input
          ref={nameField.ref}
          value={nameField.value}
          onChange={event => {
            nameField.setValue(event.target.value);
          }}
        />
      )}
    </FieldRenderer>
  );
};
```

Access an element referenced by a field:

```ts
planetField.at('name').element // ⮕ HTMLInputElement
```

Focus and blur an element referenced by a field. If a field doesn't have an associated element this is a no-op.

```ts
planetField.at('name').focus();

planetField.at('name').isFocused // ⮕ true
```

Scroll to an element:

```ts
planetField.at('name').scrollIntoView({ behavior: 'smooth' });
```

---
_Source: https://npm.io/package/@roqueform/ref-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
