diff --git a/src/components/Rating.js b/src/components/Rating.js index 04fc2ae..d5ce564 100644 --- a/src/components/Rating.js +++ b/src/components/Rating.js @@ -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,19 +14,22 @@ 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") { - value(starValue); + if (!val(readonly)) { + if (typeof onchange === "function") { + onchange(starValue); + } + else if (typeof value === "function") { + value(starValue); + } } }, }); }) ); -}; +}; \ No newline at end of file