Page MenuHomePhabricator

Checkbox, ToggleSwitch: add name prop for submittable forms
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue

When you add the name attribute which is native to input elements, the name attribute is applied to the wrapper element instead of the <input>.

For example:
<cdx-checkbox name="blah"> will generate this HTML output:

<span class="cdx-checkbox cdx-checkbox--status-default" name="blah"><input id="cdx-checkbox-13" class="cdx-checkbox__input" type="checkbox" value="false"><span class="cdx-checkbox__icon"></span><!----></span>

What happens?:

The name attribute is applied to the wrapper element instead of the <input>.

What should have happened instead?:

The name attribute should apply to the <input>.
This is already done in TextInput and Radio.

  • TextInput uses a composable to split the attributes applied to the root element <div> and child element <input>.
  • Radio uses a name prop and binds the prop to the <input>'s name attribute.

The input element's name attribute is needed when submitting a form. We'll need to fix this bug in Checkbox and ToggleSwitch.

Acceptance Criteria

  • For each component, add a name prop to the component and bind the prop to the name attribute on the <input> (similar to Radio)

Event Timeline

Catrope subscribed.

Moving to Up Next since this blocks T358934, which the Community-Tech team is currently working on.

I think we should also consider whether we should pass all HTML attributes (except class and style) to the <input> element, as TextInput does (using the useSplitAttributes composable). But we can look into that later, for now I think we should add a name prop to Checkbox and ToggleSwitch for consistency with Radio.

Catrope added a subscriber: HMonroy.

Moving to Up Next since this blocks T358934, which the Community-Tech team is currently working on.

@HMonroy said on Slack that this is no longer a blocker.

Do we really need a name prop for ToggleSwitches?
In my understanding they should never be connected even though they are a hidden checkbox under the hood.

Change #1026953 had a related patch set uploaded (by Akiel; author: Akiel):

[design/codex@main] Checkbox: Add name prop for submittable forms

https://gerrit.wikimedia.org/r/1026953

Aleksandra's patch fixes this for Checkbox, and as she points out, ToggleSwitch already uses useSplitAttributes to the name attribute is already propagated correctly there.

Change #1026953 merged by jenkins-bot:

[design/codex@main] Checkbox: Add name prop for submittable forms

https://gerrit.wikimedia.org/r/1026953

Change #1032095 had a related patch set uploaded (by VolkerE; author: VolkerE):

[mediawiki/core@master] Update Codex from 1.5.0 to 1.6.0

https://gerrit.wikimedia.org/r/1032095

Change #1032095 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from 1.5.0 to 1.6.0

https://gerrit.wikimedia.org/r/1032095