Skip to content

fix(dynamic-icon): set type="button" on the waffle variant - #3261

Merged
interactivellama merged 1 commit into
salesforce:masterfrom
zigzagdev:fix/dynamic-icon-waffle-button-type
Oct 29, 2026
Merged

interactivellama merged 1 commit into
salesforce:masterfrom
zigzagdev:fix/dynamic-icon-waffle-button-type

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #

Additional description

DynamicIcon with variant="waffle" now renders its button with type="button", so clicking it no longer submits an enclosing form.

Motivation

The waffle variant renders a <button> element but never set a type attribute. Browsers treat a button without a type as type="submit".
So when the waffle icon is placed inside a <form>, clicking it submits the form unexpectedly. This is not a regression from the rewrite. The implementation before the rewrite had the same gap.

What I have done

The component chooses its element through React.createElement(element, iconProps, ...children). The waffle branch switched element to 'button' but never added type to iconProps, which is the root cause. That branch now also sets iconProps.type = 'button'. Other variants render a span or a div and are unaffected.
I added a regression test file for DynamicIcon.
One test checks that the waffle button has type="button". The other renders the icon inside a <form>, clicks it, and asserts the submit handler is never called. The Waffle story snapshot was regenerated, and its only change is the added type="button".

Screen Shots

Before
スクリーンショット 2026-10-27 22 13 58

After
スクリーンショット 2026-10-27 10 43 08

CONTRIBUTOR checklist (do not remove)

Please complete for every pull request.

Green gate — all of these must pass locally (CI runs the same):

  • npm run lint passes with 0 errors (npm run lint:fix to auto-fix). Warnings are the tracked gradual-migration backlog; do not add new errors.
  • npm run typecheck is clean (tsc --noEmit).
  • npm test -- --run passes — this runs both Vitest projects (jsdom unit + real-browser browser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots with npm test -- --run -u and review the diff.
  • npm run build succeeds (type-check + Vite library build + .d.ts + entry shims).

Behavior & docs:

  • First-time contributors: sign the CLA (a bot will comment with instructions).
  • Added/updated Vitest + React Testing Library tests for the change (template: components/button/__tests__). New props and bug fixes should get a regression test. Tests that genuinely need a real browser (focus traversal, layout/measurement, canvas) go in a *.browser.test.jsx file (the browser project); everything else is jsdom.
  • Reviewed the component's Storybook stories: npm run storybook → http://localhost:6007/. Confirm the story actually renders and behaves (deprecated Storyshots/Karma are gone; there is no separate browser-tests server).
  • Story/example code uses the component's real prop API (e.g. render-props like onRenderContent / onRenderVisualPicker, icon props, events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check against components/<name>/__examples__.
  • Storybook Accessibility (a11y) panel shows no new violations for the affected stories.
  • If you added or changed a type, remember runtime PropTypes were removed in the TS migration — types are the contract. Ship accurate .d.ts (they're generated by the build); JS consumers rely on them via editor type-acquisition.

REVIEWER checklist (do not remove)

  • CI is green (GitHub Actions CI workflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.
  • Change has adequate test coverage; bug fixes include a regression test.
  • Reviewed the affected Storybook stories and their a11y panels.
  • Rendered markup still conforms to SLDS — check the story HTML snapshot diff (components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).
  • Public API / package surface: if exports changed, the deep-import contract still holds (@salesforce/design-system-react/components/<name> and nested paths resolve for ESM, CJS, and types). Removing/renaming a public component or export is a breaking change → feat!:/BREAKING CHANGE: and a major version bump.

The waffle variant renders a <button> without a type attribute, so the
browser treats it as type="submit". Clicking it inside a <form> submitted
the form. Set type="button" when the element is a button and add
regression tests.
@interactivellama

Copy link
Copy Markdown
Contributor

As a waffle button likely is not a submit button and is navigation. This makes sense.

@interactivellama
interactivellama merged commit 3a5224e into salesforce:master Oct 29, 2026
6 checks passed
@zigzagdev
zigzagdev deleted the fix/dynamic-icon-waffle-button-type branch October 29, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants