Skip to content

Function: toggleField()

ts
function toggleField(props: UiToggleFieldProps): Element;

Defined in: src/UI/blocks/toggleField.tsx:50

Toggle field component for boolean input. Supports both static and dynamic props based on current state.

Parameters

ParameterTypeDescription
propsUiToggleFieldPropsConfiguration object

Returns

Element

Examples

Basic usage with required props

toggleField({
  name: 'notifications',
  label: 'Enable notifications',
});

Usage with async props depending on other fields

toggleField({
  name: 'autoSave',
  label: async ({data}) => `Auto-save (${data.userType})`,
  disabled: async ({data}) => data.userType === 'guest',
});

Usage with conditional visibility and validation based on field value

toggleField({
  name: 'darkMode',
  label: 'Dark Mode',
  hidden: ({data}) => !data.supportsDarkMode,
  invalid: async ({value}) => !value ? 'Please enable dark mode' : false,
});

Matterway Assistant SDK Documentation