Editable Field

Updated:

Use for inline editing of data that is normally displayed as read-only.

Properties

The q2-editable-field element has one or more properties that support text localization. Those properties are indicated by the localizable badge in the description.

Learn more about properties.

block

If true, component expands to fill the width of its parent element.

disabled

Disables the edit button and field.

editing

Controls the edit state of the element.

errors

Determines the errors applied to the q2-input element.

See q2-input for more information.

formatModifier
format-modifier

Determines the formatModifier applied to the q2-input element.

Only applicable when type="currency".

See q2-input for more information.

hideLabel
hide-label

Hide's the field's <label> element from view.

hints

Determines the hints applied to the q2-input element.

See q2-input for more information.

label

The visible descriptor for the element. Serves as the input label while in the edit state and as a decorative label for the read state when persistentLabel is true.

Localizable
maxlength

Determines the maxLength applied to the q2-input.

See q2-input for more information.

persistentLabel
persistent-label

Displays the provided label in the read state.

truncated

Shortens long values with ellipses instead of splitting into multiple lines.

type

Determines the type applied to the q2-input element.

See q2-input for all type values.

value

Serves as the visible text while in the read state, and the default value of the input while in the edit state.

Events

The q2-editable-field element exposes events that can be used to send and receive data from the component based on user interaction.

Learn more about events.

tctChange

Emitted when the 'Edit', 'Cancel', or 'Save' buttons are clicked.

The event detail will not include a value or formattedValue if the event name is 'edit' or 'cancel'.

Event Detail Type signature

{ editing: boolean; name: "cancel" | "edit" | "save"; value?: string; formattedValue?: string; }

tctInput

Emitted when the user updates the q2-input element in the editing state.

Event Detail Type signature

{ formattedValue: string; value: string; }

Methods

The q2-editable-field element exposes methods that can be used to perform various actions on the component.

Learn more about methods.

clickCancel

Test only

Emulates clicking the cancel button, which will hide the <q2-input> field.

Type signature

clickCancel() => Promise<void>

clickEdit

Test only

Emulates clicking the edit button, which will display the <q2-input> field.

Type signature

clickEdit() => Promise<void>

clickSave

Test only

Emulates clicking the save button, saving value in the <q2-input> field, and emitting a change event.

Type signature

clickSave() => Promise<void>

setValue

Test only

Emulates clicking the edit button, and setting the value of the <q2-input> field.

If the clickSave argument is true (default), the save button will be clicked after the value is set, and a
change event will be emitted.

Type signature

setValue(value: string, options?: { clickSave?: boolean; }) => Promise<void>

Development

Using with Q2 Section

You can use q2-editable field with q2-section to provide an editable header, which can be convenient if you are needing to enable a user to change category or group names.

Some Section Content

<q2-section collapsible>
  <h2 class="mrg(0)" slot="q2-section-header">
    <q2-editable-field
      label="Edit Section Header"
      value="Editable Section Header"
      class="block"
      hide-label
      truncated
      >
    </q2-editable-field>
  </h2>
  <p>
    Some Section Content
  </p>
</q2-section>

Handling Input Validation

For inline validation as the user types, listen for the tctInput event and update the errors prop.

For validation that only runs on submit (for example, a server-side check), listen for tctChange with name: 'save' and set the errors prop to reject the value. While errors is non-empty, the component stays in edit mode; the rejected input is discarded so that a subsequent Cancel restores the last accepted value.

editableField.addEventListener('tctChange', event => {
    if (event.detail.name !== 'save') return;
    if (!isValid(event.detail.value)) {
        editableField.errors = ['Not a valid value'];
        return;
    }
    editableField.errors = undefined;
    editableField.value = event.detail.value;
});

Accessibility

Accessibility Report

Tecton components are designed and tested to be WCAG compliant when used appropriately, and do not get released without proper validation. Developers should prefer not to set ARIA attributes when using components from the Tecton Design System.

CSS Variables

The following CSS variables are available to override the default theme styles of the q2-editable-field component.

Dependencies

Many Tecton components consume other components to maintain visual and functional consistency. If you are looking for a CSS variable you think should exist but are not seeing it, it may be defined in one of the dependent components below. Either way, if you think it's something we should expose more conveniently, let us know!

Dependencies

This component uses other components in the Tecton library, including:

  • q2-input
  • q2-btn
  • q2-icon

Changelog

The changelog provides a detailed history of new features, improvements, and bug fixes going back to Tecton 1.30.0. If the button is disabled, it indicates there have been no detectable changes since then.

Show changelog (14)