Skip to content

Commit

Permalink
refactor(components/rating): optimized prop handling in useRating
Browse files Browse the repository at this point in the history
  • Loading branch information
hirotomoyamada committed May 3, 2024
1 parent bf329f4 commit 440af6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-falcons-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@yamada-ui/rating": patch
---

Optimized prop handling in `useRating`.
13 changes: 5 additions & 8 deletions packages/components/rating/src/use-rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
} from "@yamada-ui/core"
import type { FormControlOptions } from "@yamada-ui/form-control"
import {
getFormControlProperties,
formControlProperties,
useFormControlProps,
} from "@yamada-ui/form-control"
import type { RequiredMotionUIPropGetter } from "@yamada-ui/motion"
Expand All @@ -20,7 +20,6 @@ import {
handlerAll,
mergeRefs,
pickObject,
omitObject,
runIfFunc,
} from "@yamada-ui/utils"
import type {
Expand Down Expand Up @@ -181,7 +180,7 @@ export const useRating = ({
filledIcon,
...props
}: UseRatingProps) => {
let { id, ...rest } = useFormControlProps(props)
let { id, "aria-readonly": _isReadOnly, ...rest } = useFormControlProps(props)
const { disabled, readOnly } = rest

const containerRef = useRef<HTMLDivElement>(null)
Expand All @@ -196,10 +195,8 @@ export const useRating = ({
id ??= useId()
name ??= `rating-${id}`

const formControlProps = pickObject(
rest,
getFormControlProperties({ omit: ["aria-readonly"] }),
)
const formControlProps = pickObject(rest, formControlProperties)

const resolvedFractions = Math.floor(fractions)
const resolvedItems = Math.floor(items)
const decimal = 1 / resolvedFractions
Expand Down Expand Up @@ -272,7 +269,7 @@ export const useRating = ({
const getContainerProps: UIPropGetter = useCallback(
(props = {}, ref = null) => ({
ref: mergeRefs(ref, containerRef),
...omitObject(rest, ["aria-readonly"]),
...rest,
...props,
id,
onMouseEnter: handlerAll(
Expand Down

0 comments on commit 440af6a

Please sign in to comment.