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