Skip to content

Commit

Permalink
fix(VRating): expose model value in item slot
Browse files Browse the repository at this point in the history
  • Loading branch information
nekosaur committed Feb 23, 2023
1 parent 70c19a8 commit 62b4be7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vuetify/src/components/VRating/VRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type VRatingItemSlot = {
icon: IconValue
color?: string
props: Record<string, unknown>
rating: number
}

type VRatingItemLabelSlot = {
Expand Down Expand Up @@ -188,6 +189,7 @@ export const VRating = genericComponent<VRatingSlots>()({
onMouseup={ onMouseup }
onMouseenter={ onMouseenter }
onMouseleave={ onMouseleave }
onClick={ onClick }
>
<span class="v-rating__hidden">{ t(props.itemAriaLabel, value, props.length) }</span>
{
Expand All @@ -197,6 +199,7 @@ export const VRating = genericComponent<VRatingSlots>()({
props: btnProps,
value,
index,
rating: normalizedValue.value,
})
: (
<VBtn { ...btnProps } />
Expand All @@ -211,7 +214,6 @@ export const VRating = genericComponent<VRatingSlots>()({
type="radio"
value={ value }
checked={ normalizedValue.value === value }
onClick={ onClick }
onFocus={ onFocus }
onBlur={ onBlur }
ref={ index === 0 ? firstRef : undefined }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="../../../../types/cypress" />

import { VBtn } from '@/components/VBtn'
import { Application } from '../../../../cypress/templates'
import { VRating } from '../VRating'

Expand Down Expand Up @@ -148,4 +149,23 @@ describe('VRating', () => {

cy.emitted('.v-rating', 'update:modelValue').should('deep.equal', [[3.5]])
})

it('should work with item slot', () => {
cy.mount(() => (
<Application>
<VRating>
{{
item: ({ value, rating }) => (
<VBtn variant="tonal" class="mx-1" color={rating === value ? 'primary' : undefined}>{ value }</VBtn>
),
}}
</VRating>
</Application>
))

cy.get('.v-btn')
.eq(2)
.click()
.should('have.class', 'text-primary')
})
})

0 comments on commit 62b4be7

Please sign in to comment.