Page MenuHomePhabricator

Add a way to set the native type attribute on Codex Buttons
Closed, ResolvedPublic3 Estimated Story Points

Description

Summary

HTML <button> tags have a type attribute that defaults to type="submit" if they are part of a <form>. This is often not desirable, because that causes the form to be submitted when the button is clicked unless that behavior is prevented.

Currently, that native type can't be set on Codex components, because type is already a prop that does something else.

Wikit solved this with a nativeType prop: Button.vue

interface Props {
	// [...]
	/**
	 * The default behavior of the button
	 *
	 * Allowed values: `submit`, `reset`, `button`
	 */
	nativeType?: 'button' | 'submit' | 'reset';
}

It would be great if there would be a way to do something like that in Codex as well.


Implementation plan

The DST engineers decided that we would prefer to change the existing type prop to mean the native type, and add a new type called weight that has values 'normal', 'primary', 'quiet. Instead of removing type altogether and allowing the user to bind the type attribute, we will keep it as a prop so that we can clearly document the fact that the type will default to button, which is different from the native type (which defaults to submit).

This is a breaking change, so we will make the change in stages.

Stage 1: Non-breaking change
  • Add a new prop, weight, which matches the current type prop.
  • Change the type prop to refer to native button type, but continue accepting either types or weights for this prop.
  • Inside the Button component, check to see if the value provided for type is actually a weight. if so, use that value for weight, and use the default type ('button').
  • Update SearchInput to set the button type to 'submit'.
Stage 2: Communicate the change and ask devs to update
  • Once this is released, both weight and type values will work for the type prop.
  • At this time, we will ask people who are using CdxButton to update their code to change the type prop to weight, and to set the new type prop if they have a button that's a type other than 'button'.

Codesearch finds the following projects using CdxButton, which will need to be updated:

  • WikiLambda
  • GrowthExperiments
  • NearbyPages (no changes needed)
  • QuickSurveys
  • ReadingLists
  • VueTest
  • Vector
  • Citizen (skin, contains Codex styles)
Stage 3: Remove workarounds
  • Once all instances of CdxButton use have been updated to use the new weight and type props, remove the workaround code that accepts ButtonTypes for weight, tests the workaround, and demos the workaround

Acceptance criteria

  • The prop changes are made with a temporary workaround
  • The change is communicated to all dev users
  • All instances of CdxButton use are updated
  • Workarounds are removed

Event Timeline

Michael renamed this task from Add a way to set the native type attribute Codex Button to Add a way to set the native type attribute on Codex Buttons.Jul 13 2022, 7:15 PM
ldelench_wmf moved this task from Inbox to Needs Refinement on the Design-System-Team board.

I think we may have made a mistake in giving our custom "type" property the same name as the existing type attribute.

My personal view is that wherever possible we should allow native HTML attributes to "fall through" to components so that users can control them if needed without requiring additional code in Codex.

Unfortunately re-naming our Button type property is a pretty big breaking change. If we want to do this we should do it as soon as possible to get it over with. What would it make sense to re-name this property to? actionType? buttonType?

egardner raised the priority of this task from Medium to High.Jan 23 2023, 4:38 PM

Here's how we want to move forward with this work:

  • Write a patch which changes how Button works (re-names type to whatever custom name we come up with)
  • This patch should also include any other changes needed (SearchInput, Typeahead, etc)
  • DO NOT MERGE until we are ready to ship a breaking change; patch needs to have a -2 at all times (reviewers can use +1 to signal approval)
  • We will merge and release this change at an appropriate time to minimize headaches for everyone

We should also probably set the type attribute to a default value of button, since this is preferred in most cases and prevents unwanted submit behavior. We'll also need to document this. I think there are 2 ways we could do this:

  1. Allow the type attribute to be bound to the Button component. If it is, that value will be used. If not, the type attribute on the <button> element will be set to button. We'll need to document this somewhere on the Button demo page, since people might expect the default type to be submit as it is for the native element.
  2. Use a prop called type to make this more explicit. type would allow the values button, submit, and reset, and would default to button. The benefit here is that it works just like an attribute, but the fact that we're using button as the default instead of submit is documented much more clearly.

In terms of rolling this out, we should use this as an initial run of our breaking changes policy. We could change the type prop to be the actual native type (that allows values button, submit, and reset, and create a new prop for the existing button type (that allows values normal, primary, and quiet). If one of the old button type values is used for the type prop, use it instead for the new prop, and emit a warning in the console about the breaking change. As part of this change, we would also implement changes in TypeaheadSearch and SearchInput to set the type of the SearchInput button to submit.

Once all instances of the old type prop are cleaned up, we could remove this logic.

egardner set the point value for this task to 3.Feb 7 2023, 9:40 PM
AnneT changed the task status from Open to In Progress.Mar 2 2023, 9:48 PM
AnneT updated the task description. (Show Details)

Change 893823 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[design/codex@main] Button: Change `type` prop and add `weight` prop

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

Change 893823 merged by jenkins-bot:

[design/codex@main] Button: Change `type` prop and add `weight` prop

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

Moving to blocked since the next steps will be:

  • Next Codex release (next week)
  • Updating all uses of the type prop in features using Codex

Then this can be moved back to Ready for Development so we can remove the workarounds and complete this task.

Change 898895 had a related patch set uploaded (by Eric Gardner; author: Eric Gardner):

[mediawiki/core@master] Update Codex from v0.6.2 to v0.7.0

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

Change 900415 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/extensions/WikiLambda@master] Update use of CdxButton `type` and `action` props

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

Change 900423 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/extensions/GrowthExperiments@master] Rename CdxButton `type` prop to `weight`

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

Change 900424 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/extensions/QuickSurveys@master] Rename CdxButton `type` prop to `weight`

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

Change 900426 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/extensions/ReadingLists@master] Rename CdxButton `type` prop to `weight`

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

Change 900428 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/extensions/VueTest@master] Update Codex to 0.7.0 and rename `type` prop to `weight`

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

Change 900423 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] Rename CdxButton `type` prop to `weight`

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

Change 900449 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/skins/Vector@master] Rename CdxButton `type` prop to `weight`

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

Change 900428 merged by jenkins-bot:

[mediawiki/extensions/VueTest@master] Update Codex to 0.7.0 and rename `type` prop to `weight`

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

Change 900734 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[design/codex@main] Buttons, docs: use `weight` prop and set appropriate `type`

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

Change 900734 merged by jenkins-bot:

[design/codex@main] Buttons, docs: use `weight` prop and set appropriate `type`

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

Change 900449 merged by jenkins-bot:

[mediawiki/skins/Vector@master] Rename CdxButton `type` prop to `weight`

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

Change 900415 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] Update use of CdxButton `type` and `action` props

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

Change 900424 merged by jenkins-bot:

[mediawiki/extensions/QuickSurveys@master] Rename CdxButton `type` prop to `weight`

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

Change 900426 merged by jenkins-bot:

[mediawiki/extensions/ReadingLists@master] Rename CdxButton `type` prop to `weight`

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

Change 903778 had a related patch set uploaded (by Catrope; author: Catrope):

[mediawiki/core@master] Update Codex from v0.7.0 to v0.8.0

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

Catrope subscribed.

I've submitted a PR to the Citizen skin: https://github.com/StarCitizenTools/mediawiki-skins-Citizen/pull/606

I believe that means that all known uses of Codex buttons have now been updated, so we can proceed to removing the compatibility code in the next release.

Change 903778 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from v0.7.0 to v0.8.0

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

Great, thanks @Catrope! I'll move this back to "ready for development" so I can remove the workarounds.

Change 906594 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[design/codex@main] Button: Remove `type` prop and all workarounds

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

The final stage of this task is in code review; hopefully we can include it in the next Codex release

Change 906594 merged by jenkins-bot:

[design/codex@main] Button: Remove `type` prop and all workarounds

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

Change 907988 had a related patch set uploaded (by Eric Gardner; author: Eric Gardner):

[mediawiki/core@master] Update Codex from v0.8.0 to v0.9.0

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

Change 907988 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from v0.8.0 to v0.9.0

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

Test wiki created on Patch demo by KHarlan (WMF) using patch(es) linked to this task:
https://patchdemo.wmflabs.org/wikis/cfdfa13682/w

Test wiki on Patch demo by KHarlan (WMF) using patch(es) linked to this task was deleted:

https://patchdemo.wmflabs.org/wikis/cfdfa13682/w/