Page MenuHomePhabricator

Checkbox, Radio: Enable "other" text field
Open, Needs TriagePublic

Description

Background

A common use case across products is a checkbox or radio that, when checked, displays a text input or text area to capture further user input. This is included in our form guidelines:

image.png (628×1 px, 55 KB)

Given the prevalence of this use case, and that we want to standardize its design, we should build this into the Checkbox and Radio components. Note that we may want this for other components in the future as well (e.g. for "select or other" fields, something that exists in HTMLForm and is being used on Special:Block).

Known use cases

Captura de pantalla 2024-04-25 a las 11.27.56.png (1×562 px, 112 KB)
Trust & Safety Product Team (Figma).

Others:

  • In Adiutor, there's a checkbox that shows a text input field when checked. I will note that it's not styled according to our designs (see screenshot)
  • In ReportIncident, there's a checkbox that shows a text area when checked. I don't have this installed locally and am unsure of whether it's in production anywhere, but hopefully the code can help

Design spec

Link it here once it's completed.

Checkbox spec sheetRadio spec sheet

Guidelines

Link it here once it's completed.

Google doc with the Guidelines

Implementation

We will want to add a few new props to Checkbox and Radio (prop names are open for debate)

  • showOther: a boolean prop that, when true, will add a TextInput or TextArea
  • otherComponent: a prop that can either be 'text' or 'textarea', defaulting to 'text' (the name of these strings is also up for debate. This could also be a boolean prop like useTextArea or something)
  • otherValue: the value of that input, bound with v-model:otherValue

The Checkbox and Radio templates will need to be updated to conditionally show the TextInput or TextArea, and appropriate styles will be added.

Finally, we'll need tests and demos.


Acceptance criteria

Design

  • Design the Figma spec sheet and include its link in this task:
  • Include a list of keyboard shortcuts to navigate the component (if needed)
  • Provide Guidelines for the new properties of Checkbox and Radio
  • Update the main component in the Figma library. This step will be done by a DST member.

Code

  • A TextInput or TextArea can be conditionally added below a Checkbox or Radio
  • The TextInput or TextArea is styled in line with the Figma designs
  • The new functionality is covered by unit tests
  • A new demo is added to each component's demo page showing the new functionality

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Some notes:

  • We'll need to add a design spec to this task
  • If this task is implemented by someone outside the Design System Team, we can talk about splitting up the acceptance criteria to make the work more manageable. For example, a Codex volunteer could implement the functionality, but then someone from the Design System Team could add the new demos
CCiufo-WMF subscribed.

Just to confirm, is this a hard blocker to T362583?

@AnneT provided some examples of similar UI:

  • In Adiutor, there's a checkbox that shows a text input field when checked. I will note that it's not styled according to our designs (see screenshot)
  • In ReportIncident, there's a checkbox that shows a text area when checked.

{F48839978}

Hi @CCiufo-WMF

Yes that's correct, it's not a hard blocker.

If you are happy to, then the contractors can develop a version for now and work to update it with the Codex component when ready?

In the meantime I will work on the design spec with Bárbara's guidance.

Just to confirm, is this a hard blocker to T362583?

@AnneT provided some examples of similar UI:

  • In Adiutor, there's a checkbox that shows a text input field when checked. I will note that it's not styled according to our designs (see screenshot)
  • In ReportIncident, there's a checkbox that shows a text area when checked.

{F48839978}

Hi @CCiufo-WMF

Yes that's correct, it's not a hard blocker.

Perfect, thank you!

If you are happy to, then the contractors can develop a version for now and work to update it with the Codex component when ready?

That sounds good. Let us know if they run into any issues. To confirm: are the contractors also open to upstreaming this to Codex? That might be faster than waiting for us to develop it.

Implementation

We will want to add a few new props to Checkbox and Radio (prop names are open for debate)

  • showOther: a boolean prop that, when true, will add a TextInput or TextArea
  • otherComponent: a prop that can either be 'text' or 'textarea', defaulting to 'text' (the name of these strings is also up for debate. This could also be a boolean prop like useTextArea or something)
  • otherValue: the value of that input, bound with v-model:otherValue

The Checkbox and Radio templates will need to be updated to conditionally show the TextInput or TextArea, and appropriate styles will be added.

The proposed implementation seems a little clunky to me, and also inflexible. If we need to go back and later add support for a Select or Combobox component in the same way, we'd have to do additional work. Also, what if someone wants more custom markup beneath the text area (like a link to docs or a privacy policy)?

For a use case that is potentially very open-ended, I think we are better off handling this as a slot. Maybe we'd call it something like #customValue. This slot could hold arbitrary content inside an element that appears inline with the checkbox/radio button (unlike the #description slot content, which appears beneath). The user could take care of binding the value themselves. We could provide an example of how to set this up similar to our custom dialog examples.