Problem Object Object in Rating

This commit is contained in:
2026-03-31 19:28:22 +02:00
parent e2f5932810
commit 3619239b9d

View File

@@ -3,9 +3,7 @@ import { val } from "../core/utils.js";
/** RATING */
export const Rating = (props) => {
const { value, count = 5, mask = "mask-star", readonly = false, ...rest } = props;
// Generamos un ID único para el grupo de radio buttons
const { value, count = 5, mask = "mask-star", readonly = false, onchange, ...rest } = props;
const ratingGroup = `rating-${Math.random().toString(36).slice(2, 7)}`;
return $html(
@@ -16,17 +14,20 @@ export const Rating = (props) => {
},
Array.from({ length: val(count) }, (_, i) => {
const starValue = i + 1;
return $html("input", {
type: "radio",
name: ratingGroup,
class: `mask ${mask}`,
"aria-label": `${starValue} star`,
checked: () => Math.round(val(value)) === starValue,
onchange: () => {
if (!val(readonly) && typeof value === "function") {
if (!val(readonly)) {
if (typeof onchange === "function") {
onchange(starValue);
}
else if (typeof value === "function") {
value(starValue);
}
}
},
});
})