5.0.0 ā€¢ Published 4 months ago

@roqueform/ref-plugin v5.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

DOM reference plugin for Roqueform

Associates Roqueform fields with DOM elements.

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

Overview

šŸ”Ž API documentation is available here.

This plugin doesn't require any rendering framework. To simplify the usage example, we're going to use the React integration.

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:

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.

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

planetField.at('name').isFocused // ā®• true

Scroll to an element:

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

4 months ago

4.0.1

9 months ago

4.0.0

1 year ago

3.0.0

1 year ago

2.1.0

2 years ago

2.0.0

2 years ago