Skip to content
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: RatingGroup component #516

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
chore: attribution and docs nitpicks
  • Loading branch information
HBS999 committed Nov 9, 2024
commit ea8a123d3a96a310d81ce271f699f206e53ce5d4
3 changes: 2 additions & 1 deletion apps/docs/src/routes/docs/core/components/rating-group.mdx
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import { Root, Label, ... } from "@kobalte/core/rating-group";

## Features

- Precise ratings with half-value increments.
- Syncs with form reset events.
- Group and rating labeling support for assistive technology.
- Can be controlled or uncontrolled.
HBS999 marked this conversation as resolved.
Show resolved Hide resolved
@@ -141,7 +142,7 @@ transition: fill 200ms cubic-bezier(0.2, 0, 0, 1);
fill: hsl(200 98% 39%);
}

````
```

</TabsSnippets.Content>
{/* <!-- prettier-ignore-end --> */}
9 changes: 0 additions & 9 deletions packages/core/src/rating-group/rating-group-root.tsx
Original file line number Diff line number Diff line change
@@ -175,15 +175,6 @@ export function RatingGroupRoot<T extends ValidComponent = "div">(
}

setValue(newValue);

// Sync all radio input checked state in the group with the selected value.
// This is necessary because checked state might be out of sync
// (ex: when using controlled radio-group).
if (ref)
for (const el of ref.querySelectorAll("[role='radio']")) {
const radio = el as HTMLInputElement;
radio.checked = Number(radio.value) === value();
}
},
allowHalf: () => local.allowHalf,
orientation: () => local.orientation!,
8 changes: 8 additions & 0 deletions packages/core/src/rating-group/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* Portions of this file are based on code from zag.
* MIT License, Copyright 2021 Chakra UI.
*
* Credits to the Chakra UI team:
* https://github.com/chakra-ui/zag/blob/87ebdd171d5e28fffe2cec7d0b0d5f5a68601963/packages/utilities/dom-event/src/get-event-point.ts
*/

type PointType = "page" | "client";
HBS999 marked this conversation as resolved.
Show resolved Hide resolved
type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent;
type Point = {
Loading