Skip to content

Conversation

@markvarga8
Copy link
Contributor

@markvarga8 markvarga8 commented Aug 18, 2025

Describe the PR

Closes #2752

  • Added #icon-clear slot to BFormRating for customizing the clear/reset icon.
  • Preserved default SVG icon as fallback when no slot is provided.

Small replication

Kepernyofelvetel.2025-08-18.-.13.00.24.mov

PR checklist

What kind of change does this PR introduce? (check at least one)

  • Bugfix 🐛 - fix(...)
  • Feature - feat(...)
  • ARIA accessibility - fix(...)
  • Documentation update - docs(...)
  • Other (please describe)

The PR fulfills these requirements:

  • Pull request title and all commits follow the Conventional Commits convention or has an override in this pull request body This is very important, as the CHANGELOG is generated from these messages, and determines the next version type. Pull requests that do not follow conventional commits or do not have an override will be denied

Summary by CodeRabbit

  • New Features

    • BFormRating now supports a customizable clear icon via a new icon-clear slot. Default appearance remains unchanged if not overridden.
  • Documentation

    • Added a “Custom clear icon” section with a new demo showcasing how to replace the clear icon.
    • Updated examples to illustrate using the icon-clear slot.
  • Tests

    • Added tests covering default clear icon fallback, custom icon-clear slot rendering, click-to-clear behavior, and readonly state not rendering the clear control.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 18, 2025

Walkthrough

Adds a new named slot "icon-clear" to BFormRating, replacing the inline SVG with a slot-backed default. Updates types and docs data to include the slot. Adds documentation and a demo showing custom clear content. Extends tests to cover default, custom slot, and readonly behaviors.

Changes

Cohort / File(s) Summary
BFormRating component & slots typing
packages/bootstrap-vue-next/src/components/BFormRating/BFormRating.vue, packages/bootstrap-vue-next/src/types/ComponentSlots.ts
Introduced named slot icon-clear with default SVG fallback; updated BFormRatingSlots to include optional icon-clear (no props).
Unit tests for clear icon
packages/bootstrap-vue-next/src/components/BFormRating/BFormRating.spec.ts
Added tests for fallback clear icon, custom #icon-clear slot rendering, and readonly gating of clear UI and behavior.
Docs metadata
apps/docs/src/data/components/FormRating.data.ts
Adjusted slots map key to 'default'; added 'icon-clear' slot entry with description.
Docs content & demo
apps/docs/src/docs/components/form-rating.md, apps/docs/src/docs/components/demo/RatingCustomClear.vue
Documented #icon-clear usage; added demo component showing custom clear button with show-clear and reactive rating display.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant R as BFormRating
  participant S as icon-clear Slot (optional)

  U->>R: Interact (showClear enabled)
  alt Slot provided
    R->>S: Render custom clear content
  else No slot
    R->>R: Render default clear SVG
  end
  U->>R: Click clear
  R-->>U: emit(update:modelValue, 0)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • dwgray

Poem

A nibble, a hop, a gleaming star,
The clear icon now custom by far.
Swap a slot, reset to zero—bing!
Tests all pass; the bells now ring.
I thump in joy, code neat and fair,
A rabbit’s cheer for “icon-clear.” 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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

🔭 Outside diff range comments (4)
apps/docs/src/docs/components/form-rating.md (3)

109-116: Correct the clear behavior and disabled note

Two issues:

  • The component clears to 0 (not null) on click.
  • The note mentions disabled, but that state is not implemented yet and the component currently gates only on readonly.

Apply this diff:

-Optionally show a clear icon via the `show-clear` prop. The value will be set to `null` when the clear icon is clicked.
+Optionally show a clear icon via the `show-clear` prop. The value will be set to `0` when the clear icon is clicked.
@@
-**Notes:**
-
-- The clear icon will not be shown when the props `readonly` or `disabled` are set.
+**Notes:**
+
+- The clear icon will not be shown when the prop `readonly` is set.

182-183: Update implementation note to reflect actual markup

Docs say the root element is an <output>, but the component uses a <div role="slider">. Please update the implementation notes to match.


150-153: Remove or Update “Icon props (Advanced)” Section

The icon-empty, icon-half, icon-full, and icon-clear props no longer exist on BFormRating. Instead, custom icons are provided via slots:

  • Use the default slot (props: { starIndex, isFilled, isHalf }) to override empty/half/full star icons.
  • Use the icon-clear slot to override the clear-button icon.

Please remove or rewrite the “Icon props (Advanced)” section so it reflects slot-based customization rather than nonexistent props.

packages/bootstrap-vue-next/src/components/BFormRating/BFormRating.spec.ts (1)

222-259: Wrap new tests in a describe block and enable auto-unmount

The three added tests are outside the existing describe('rating', ...) where enableAutoUnmount(afterEach) is called. As-is, these wrappers will not be auto-unmounted, which can lead to leaking DOM and flaky tests over time. Group them under a describe and call enableAutoUnmount to match the rest of the suite.

Apply this diff to encapsulate the new tests and ensure consistent teardown:

+describe('rating: icon-clear slot', () => {
+  enableAutoUnmount(afterEach)
 it('renders fallback clear icon when showClear is true (no slot provided)', async () => {
   const wrapper = mount(BFormRating, {
     props: {modelValue: 3, showClear: true, readonly: false},
   })
   const clearArea = wrapper.find('.clear-button-spacing')
   expect(clearArea.exists()).toBe(true)

   await clearArea.trigger('click')
   expect(wrapper.emitted('update:modelValue')).toBeTruthy()
   expect(wrapper.emitted('update:modelValue')![0]).toEqual([0])
 })
 
 it('uses #icon-clear slot content when provided', async () => {
   const wrapper = mount(BFormRating, {
     props: {modelValue: 4, showClear: true},
     slots: {
       'icon-clear': '<button id="custom-clear" type="button">Clear</button>',
     },
   })
   const clearArea = wrapper.find('.clear-button-spacing')
   expect(clearArea.exists()).toBe(true)
   expect(wrapper.find('#custom-clear').exists()).toBe(true)

   await clearArea.trigger('click')
   expect(wrapper.emitted('update:modelValue')).toBeTruthy()
   expect(wrapper.emitted('update:modelValue')![0]).toEqual([0])
 })
 
 it('does not render clear when readonly is true', () => {
   const wrapper = mount(BFormRating, {
     props: {showClear: true, readonly: true},
     slots: {'icon-clear': '<span id="slot-should-not-render">X</span>'},
   })
   expect(wrapper.find('.clear-button-spacing').exists()).toBe(false)
   expect(wrapper.find('#slot-should-not-render').exists()).toBe(false)
 })
+})
🧹 Nitpick comments (6)
packages/bootstrap-vue-next/src/components/BFormRating/BFormRating.vue (1)

175-196: Optional: add keyboard affordances to clear and jump to ends

Currently, arrow keys work, but there is no keyboard shortcut to clear. Consider enhancing onKeydown to support Home (min), End (max), and Delete/Backspace (clear to 0). This improves accessibility and avoids making the clear container focusable (which could conflict when users provide a focusable element in the #icon-clear slot).

Example update (outside the changed lines, shown for clarity):

function onKeydown(e: KeyboardEvent) {
  if (props.readonly) return

  let newValue = localValue.value

  switch (e.key) {
    case 'ArrowRight':
    case 'ArrowUp':
      newValue = Math.min(newValue + 1, clampedStars.value)
      break
    case 'ArrowLeft':
    case 'ArrowDown':
      newValue = Math.max(newValue - 1, 0)
      break
    case 'Home':
      newValue = 0
      break
    case 'End':
      newValue = clampedStars.value
      break
    case 'Delete':
    case 'Backspace':
      newValue = 0
      break
    default:
      return
  }

  e.preventDefault()
  localValue.value = newValue
}
apps/docs/src/data/components/FormRating.data.ts (1)

104-106: Clarify that the slot is not scoped

The icon-clear slot takes no scope. Consider reflecting that in the description.

Apply this diff:

-          description: 'Content for the optional clear button',
+          description: 'Content for the optional clear button (not scoped)',
apps/docs/src/docs/components/demo/RatingCustomClear.vue (1)

1-18: Great demo; minor consistency nit

The example clearly demonstrates the new slot. For consistency with other docs examples, consider using <BButton> casing and adding an accessible label.

Apply this diff:

-        <b-button variant="dark"> Clear </b-button>
+        <BButton variant="dark" aria-label="Clear rating" type="button">Clear</BButton>
packages/bootstrap-vue-next/src/components/BFormRating/BFormRating.spec.ts (3)

223-233: Strengthen the fallback clear icon assertion (avoid duplicating an existing behavior-only test)

This test currently duplicates the earlier "has clear button to reset rating to 0" behavior test (Lines 110–124) without actually asserting the fallback icon renders. Add a minimal check to prove the default SVG fallback is present, differentiating this test from the previous one.

   const clearArea = wrapper.find('.clear-button-spacing')
   expect(clearArea.exists()).toBe(true)
+  // Assert that the default fallback icon (SVG) is rendered when no slot is provided
+  expect(clearArea.find('svg').exists()).toBe(true)

Optionally, consider consolidating the earlier clear-button behavior test with this one to reduce redundancy.


235-249: Trigger click on the actual slotted control to verify slot-driven interaction

Clicking the container works today because the click handler is on the wrapper, but it doesn't validate that a custom slotted control remains operable. Trigger the click on the slotted button to ensure the slot content can drive the clear action.

-  await clearArea.trigger('click')
+  await wrapper.find('#custom-clear').trigger('click')

251-258: Also assert no emission occurs in readonly mode

This test verifies the clear UI isn’t rendered when readonly is true. Add a quick check that no update event was emitted as an extra guard.

   expect(wrapper.find('.clear-button-spacing').exists()).toBe(false)
   expect(wrapper.find('#slot-should-not-render').exists()).toBe(false)
+  expect(wrapper.emitted('update:modelValue')).toBeFalsy()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 35a419f and b5666b3.

📒 Files selected for processing (6)
  • apps/docs/src/data/components/FormRating.data.ts (2 hunks)
  • apps/docs/src/docs/components/demo/RatingCustomClear.vue (1 hunks)
  • apps/docs/src/docs/components/form-rating.md (1 hunks)
  • packages/bootstrap-vue-next/src/components/BFormRating/BFormRating.spec.ts (1 hunks)
  • packages/bootstrap-vue-next/src/components/BFormRating/BFormRating.vue (1 hunks)
  • packages/bootstrap-vue-next/src/types/ComponentSlots.ts (1 hunks)
🔇 Additional comments (5)
packages/bootstrap-vue-next/src/types/ComponentSlots.ts (1)

283-286: Slot typing addition for BFormRating looks correct and consistent

Adding 'icon-clear'?: (props: Record<string, never>) => any is aligned with existing conventions for non-scoped slots in this file. Keeping 'default' as a string-literal key is also consistent elsewhere.

packages/bootstrap-vue-next/src/components/BFormRating/BFormRating.vue (1)

18-32: Non-breaking slot-ization of the clear icon looks good

Wrapping the existing SVG in a named icon-clear slot preserves the default UI while enabling customization. The click handler and gating are unchanged, so behavior remains backward compatible.

apps/docs/src/data/components/FormRating.data.ts (2)

87-87: Using the string-literal 'default' slot key is correct

This aligns with how other components enumerate slot names in the docs data. No issues.


35-39: Verify default for precision vs. component behavior

Docs list precision default as undefined, while the component code defaults precision to 0. For consistency across docs and implementation, consider updating the default to 0 here or aligning the component default.

apps/docs/src/docs/components/form-rating.md (1)

117-123: Docs section addition reads well and matches the new slot

Clear, accurate guidance that the #icon-clear slot is not scoped, with a linked demo. Nicely done.

@markvarga8 markvarga8 changed the title feat(BFormRating): added icon-clear slot (#2752) feat(BFormRating): added icon-clear slot Aug 18, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 18, 2025

bsvn-vite-ts

npm i https://pkg.pr.new/bootstrap-vue-next/bootstrap-vue-next@2809
npm i https://pkg.pr.new/bootstrap-vue-next/bootstrap-vue-next/@bootstrap-vue-next/nuxt@2809

commit: b5666b3

@VividLemon VividLemon merged commit 4120f3d into bootstrap-vue-next:main Aug 18, 2025
5 checks passed
xvaara added a commit that referenced this pull request Aug 19, 2025
…keover

* upstream/main: (21 commits)
  feat(b-form-rating): add `icon-clear` slot (#2809)
  docs: fix dead links, enable rule (#2808)
  chore: release main (#2801)
  docs: Fix navbar collapse behavior (#2802)
  docs: fix code tabs on getting started and icons pages (#2805)
  docs: fix missing data and use a stronger schema to catch missing errors (#2806)
  feat(BPopover): add explicit props for focus and hover triggers (#2795)
  fix(BNavbar): changed autoClose to noAutoClose and fix the documention mistake about it.
  fix: ssr in scrollspy
  docs: clean up css selector
  docs: fix on-this-page when examples use header tags
  docs(migration): add component aliases guidelines (#2771)
  chore: upgrade dependencies and address all lint warnings (#2785)
  chore: release main (#2769)
  fix(BDropdown): prevent hydration warning in nuxt production mode (#2768)
  docs(BTabs): Updates based on v-model changes (#2760)
  docs(table): fix missing anchor in `BTableLite` and `BTableSimple` links (#2759)
  docs(BFormRating): Parity pass (#2749)
  docs: fix typo in breadcrumb documentation (#2756)
  docs: Fix empty-text and empty-filtered-text description as they require show-empty to be set (#2755)
  ...
@github-actions github-actions bot mentioned this pull request Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BFormRating: Implement slot for the clear button

2 participants