Skip to content

Consistent read-only state for form components #415

Description

@akselkvitberg

Version: @bcc-code/component-library-vue 1.4.36

We show forms to users who may view but not edit them. There is no single way to render such a form as read-only with the library today, so every app works around it differently.

Everything below was reproduced in a bare Vite + Vue app that only does app.use(BccComponentLibrary) and imports @bcc-code/component-library-vue/style.css. There is no Tailwind, no other UI library and no app CSS.

What we ran into

  1. BccSelect and BccInputChips accept readonly but ignore it. They re-export PrimeVue Select and InputChips, which have no such prop, so readonly lands on the root element as a plain attribute. A readonly BccSelect still opens its dropdown, and a readonly BccInputChips still adds a tag on Enter and still shows each chip's remove icon. BccInput, BccTextarea and BccCheckbox do support readonly, so a mixed form ends up part readonly and part disabled.
  2. Readonly fields look editable. Readonly BccInput, BccTextarea and BccSelect compute to the same background (#fff) and text colour (rgb(41, 42, 46)) as editable ones, so users only find out when they try to type.
  3. Disabled fields fade the value to about 2:1 contrast. Disabled BccInput, BccTextarea and the BccSelect label use --p-inputtext-disabled-color (rgba(8, 15, 33, .29)) on --p-inputtext-disabled-background (rgba(5, 21, 36, .06)), which is 1.93:1. That's fine for a control that really is unavailable (WCAG exempts inactive components), but it makes disabled unusable as a stand-in for read-only, where people need to read the value.
  4. Disabled BccInputChips is styled differently from the other disabled fields.
    • Its background is --p-inputchips-disabled-background (#dddee1), so it renders darker than the inputs next to it.
    • It fades through opacity: 0.6 on the whole component, about 3.3:1 for the chip text, instead of the disabled text colour.
    • It keeps showing each chip's remove icon.
  5. A readonly BccCheckbox still fires a native change on click. The model stays unchanged, but the native input flips to checked, and a form-level @change listener, such as unsaved-changes tracking, still sees an edit.

Suggestion

  • Add a real readonly to BccSelect and BccInputChips. Readonly should mean: focusable, value selectable, no dropdown or editing, chip remove icons hidden.
  • Give readonly fields a visual style of their own in the theme, e.g. a muted background with full-contrast text, used the same way across BccInput, BccTextarea, BccSelect, BccInputChips and BccCheckbox.
  • Style disabled InputChips the same way as the other disabled inputs (same background token, same text treatment) and hide the chip remove icon.
  • Stop the native change event on a readonly BccCheckbox (e.g. preventDefault on click), so the native state matches the model.

Our workaround for now is a scoped style that gives readonly and disabled fields the same muted background and full-contrast text, and hides the chip remove icons. We'd rather delete it than keep it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions