Fieldset

import Fieldset from 'frui/fields/Fieldset';
Copy

Props

The following props are accepted by Fieldset.

NameTypeRequiredNotes
addstringNoAdd button text
classNamestringNoStandard HTML class names applied to the add button
configObjectNoObject that is directly passed to custom fieldset
defaultValuestring[]NoDefault value (uncontrolled)
emptyValueanyNoValue used when creating a new fieldset
errorstring|booleanNoAny error message
namestringNoUsed for react server components.
placeholderstringNoPlaceholders for input values.
onUpdateFunctionNoEvent handler when value updates
styleCSS ObjectNoStandard CSS object applied to the add button
valuestring[]NoDefault value (controlled)

Basics

A  Fieldset is a set of fields grouped together to be copied and processed as one field. Examples of fieldsets are Metadata and Textlist. The following shows how to create a basic fieldset:

//types
import type { FieldsProps, FieldsetProps } from 'frui/Fieldset';
//make fieldset
import make from 'frui/Fieldset';
//fields
export function InputFields(props: FieldsProps<string>) {
  const { values, index, error, set } = props;
  const handlers = {
    update: (value: string) => {
      const newValues = [ ...(values || []) ]
      newValues[index] = value;
      set(newValues);
    },
    remove: () => {
      const newValues = [ ...(values || []) ];
      newValues[index] = undefined;
      set(newValues);
    }
  };
  return (
    <div>
      <input 
        defaultValue={values ? values[index]: undefined} 
        onChange={e => handlers.update(e.target.value)} 
      />
      <button onClick={handlers.remove}>
        &times;
      </button>
    </div>
  );
};
//make fieldset
const Fieldset = make<string>(InputFields);
//ex. <InputList add="Add Input" value={['foo', 'bar']} />
export default function InputList(props: FieldsetProps<string>) {
  return (
    <Fieldset {...props} emptyValue="" />
  );
};
Copy

Custom Styles

You can add your own custom class to selects or use the  frui-fieldset-add CSS class.