Skip to content

Add support for HTML attributes on buttons and cancelIcon#3370

Merged
RobbieTheWagner merged 3 commits intomainfrom
data-attributes
Feb 19, 2026
Merged

Add support for HTML attributes on buttons and cancelIcon#3370
RobbieTheWagner merged 3 commits intomainfrom
data-attributes

Conversation

@RobbieTheWagner
Copy link
Member

@RobbieTheWagner RobbieTheWagner commented Feb 19, 2026

Summary by CodeRabbit

  • New Features

    • Support for custom HTML attributes on buttons and cancel icons, allowing additional attributes (data-, aria-, etc.) to be applied.
  • Documentation

    • Reflowed and clarified usage guide text, expanding option descriptions and examples for attributes and related options.
  • Tests

    • Expanded unit tests covering attribute application, value stringification, and protection of core attributes.

@vercel
Copy link

vercel bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
shepherd-docs Ready Ready Preview, Comment Feb 19, 2026 2:45am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
shepherd-landing Skipped Skipped Feb 19, 2026 2:45am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds optional attrs to step button and cancel-icon options, spreads those attributes into the rendered button elements, updates docs formatting, and adds unit tests verifying attribute application and protection of core attributes.

Changes

Cohort / File(s) Summary
Type Definitions
shepherd.js/src/step.ts
Added attrs?: Record<string, string | number | boolean> to StepOptionsButton and StepOptionsCancelIcon with docs and examples.
Component Implementation
shepherd.js/src/components/shepherd-button.ts, shepherd.js/src/components/shepherd-cancel-icon.ts
Spread provided attrs into the constructed button elements so arbitrary HTML attributes (e.g., data-*, aria-*) are applied; existing core attributes remain enforced.
Unit Tests
shepherd.js/test/unit/components/shepherd-button.spec.js, shepherd.js/test/unit/components/shepherd-header.spec.js
Added tests for single/multiple attrs, non-string value stringification, protection of non-overridable core attributes, empty/undefined attrs, and special-character handling.
Documentation
docs-src/src/content/docs/guides/usage.md
Reflowed and reformatted text and examples across several sections for readability; no behavioral or API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nibble code and tuck on tags so neat,

data-* and aria-* snugly meet,
Buttons wear attributes like a hat,
Core props guarded — we won’t let that,
Hopping off now — this patch is sweet.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding support for HTML attributes on buttons and cancelIcon components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch data-attributes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qltysh
Copy link

qltysh bot commented Feb 19, 2026

Qlty

Coverage Impact

This PR will not change total coverage.

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
shepherd.js/src/components/shepherd-cancel-icon.ts (1)

17-17: ?? is more semantically precise than || here.

Since attrs is typed as Record<string, string | number | boolean> | undefined, it can never be falsy except when undefined/null. Using || works correctly but implies falsiness checking, whereas ?? (nullish coalescing) expresses the true intent. The same applies to shepherd-button.ts line 25.

♻️ Suggested change
-      ...(cancelIcon.attrs || {}),
+      ...(cancelIcon.attrs ?? {}),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shepherd.js/src/components/shepherd-cancel-icon.ts` at line 17, Replace the
use of the logical OR fallback with the nullish coalescing operator when
spreading attribute objects: change the spread from ...(cancelIcon.attrs || {})
to ...(cancelIcon.attrs ?? {}) in shepherd-cancel-icon (referencing the
cancelIcon.attrs symbol), and make the analogous change in shepherd-button.ts at
the place using attrs (line referencing the attrs spread) so that only
null/undefined falls back to an empty object rather than any falsy value.
shepherd.js/test/unit/components/shepherd-button.spec.js (1)

180-213: Test gap: action-less button with onclick in attrs is untested.

The "does not override core button attributes" test supplies a real action, so onclick: action (a non-null function) is always set by h. The untested edge case (tied to the concern in the component) is a button with action: undefined and attrs: { onclick: 'someCode' }, where onclick: null is passed as the core value and h may skip clearing it.

🧪 Proposed additional test
+    it('does not persist onclick from attrs on action-less buttons', () => {
+      const button = createShepherdButton(
+        {
+          attrs: { onclick: 'alert("unexpected")' }
+        },
+        undefined
+      );
+      container.appendChild(button);
+
+      // The string onclick attribute should not survive; no inline handler
+      expect(button.onclick).toBeNull();
+      expect(button.getAttribute('onclick')).toBeNull();
+    });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shepherd.js/test/unit/components/shepherd-button.spec.js` around lines 180 -
213, Add a new unit test for createShepherdButton that covers the edge case
where action is undefined but attrs includes an onclick string: call
createShepherdButton with action: undefined (or omitted) and attrs: { onclick:
'someCode', 'data-test': 'x' } and a mockStep, append to container, then assert
the core onclick is not set on the rendered button (e.g.,
button.getAttribute('onclick') is null or
button).not.toHaveAttribute('onclick'), while still verifying other core
attributes (type, class includes 'shepherd-button',
disabled/tabindex/aria-label) remain protected and non-conflicting custom attrs
(like data-test) are applied; place this alongside the existing "does not
override core button attributes" test to ensure the h/createShepherdButton path
that clears onclick behaves correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs-src/src/content/docs/guides/usage.md`:
- Around line 260-262: The docs add a broken link to /guides/custom-attributes;
fix by either adding the missing guide file or removing/adjusting the link and
referencing the existing JSDoc for StepOptionsButton.attrs instead—update the
usage.md line that links `[Custom Attributes guide](/guides/custom-attributes)`
to point to the inline documentation (mention StepOptionsButton.attrs JSDoc) or
replace the link with a valid path to a newly created custom-attributes.md guide
so the reference resolves.

---

Nitpick comments:
In `@shepherd.js/src/components/shepherd-cancel-icon.ts`:
- Line 17: Replace the use of the logical OR fallback with the nullish
coalescing operator when spreading attribute objects: change the spread from
...(cancelIcon.attrs || {}) to ...(cancelIcon.attrs ?? {}) in
shepherd-cancel-icon (referencing the cancelIcon.attrs symbol), and make the
analogous change in shepherd-button.ts at the place using attrs (line
referencing the attrs spread) so that only null/undefined falls back to an empty
object rather than any falsy value.

In `@shepherd.js/test/unit/components/shepherd-button.spec.js`:
- Around line 180-213: Add a new unit test for createShepherdButton that covers
the edge case where action is undefined but attrs includes an onclick string:
call createShepherdButton with action: undefined (or omitted) and attrs: {
onclick: 'someCode', 'data-test': 'x' } and a mockStep, append to container,
then assert the core onclick is not set on the rendered button (e.g.,
button.getAttribute('onclick') is null or
button).not.toHaveAttribute('onclick'), while still verifying other core
attributes (type, class includes 'shepherd-button',
disabled/tabindex/aria-label) remain protected and non-conflicting custom attrs
(like data-test) are applied; place this alongside the existing "does not
override core button attributes" test to ensure the h/createShepherdButton path
that clears onclick behaves correctly.

@vercel vercel bot temporarily deployed to Preview – shepherd-landing February 19, 2026 02:44 Inactive
@vercel vercel bot temporarily deployed to Preview – shepherd-landing February 19, 2026 02:44 Inactive
@RobbieTheWagner RobbieTheWagner merged commit 7db564d into main Feb 19, 2026
7 of 8 checks passed
@RobbieTheWagner RobbieTheWagner deleted the data-attributes branch February 19, 2026 02:48
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.

1 participant

Comments