-
-
Notifications
You must be signed in to change notification settings - Fork 174
feat(BFormRating): added icon-clear slot
#2809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(BFormRating): added icon-clear slot
#2809
Conversation
|
|
WalkthroughAdds 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 noteTwo issues:
- The component clears to
0(notnull) on click.- The note mentions
disabled, but that state is not implemented yet and the component currently gates only onreadonly.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 markupDocs 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)” SectionThe
icon-empty,icon-half,icon-full, andicon-clearprops 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-unmountThe 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 endsCurrently, arrow keys work, but there is no keyboard shortcut to clear. Consider enhancing
onKeydownto 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-clearslot).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 scopedThe
icon-clearslot 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 nitThe 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 interactionClicking 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 modeThis 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.
📒 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 consistentAdding
'icon-clear'?: (props: Record<string, never>) => anyis 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 goodWrapping the existing SVG in a named
icon-clearslot 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 correctThis aligns with how other components enumerate slot names in the docs data. No issues.
35-39: Verify default for precision vs. component behaviorDocs list
precisiondefault asundefined, while the component code defaultsprecisionto0. For consistency across docs and implementation, consider updating the default to0here 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 slotClear, accurate guidance that the
#icon-clearslot is not scoped, with a linked demo. Nicely done.
icon-clear slot (#2752)icon-clear slot
commit: |
…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) ...
Describe the PR
Closes #2752
Small replication
Kepernyofelvetel.2025-08-18.-.13.00.24.mov
PR checklist
What kind of change does this PR introduce? (check at least one)
fix(...)feat(...)fix(...)docs(...)The PR fulfills these requirements:
CHANGELOGis 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 deniedSummary by CodeRabbit
New Features
Documentation
Tests