Refactor #5437 - For Rating

This commit is contained in:
tugcekucukoglu 2024-03-26 10:28:22 +03:00
parent 8efb1a5eea
commit aedd31e8e6
6 changed files with 12 additions and 66 deletions

View file

@ -24,7 +24,7 @@ export default {
},
cancel: {
type: Boolean,
default: true
default: false
},
onIcon: {
type: String,

View file

@ -181,7 +181,8 @@ export interface RatingProps {
stars?: number | undefined;
/**
* When specified a cancel icon is displayed to allow clearing the value.
* @defaultValue true
* @deprecated since v4.0.0-beta.1
* @defaultValue false
*/
cancel?: boolean | undefined;
/**

View file

@ -106,8 +106,13 @@ export default {
this.isFocusVisibleItem = true;
},
onOptionSelect(event, value) {
this.focusedOptionIndex = value;
this.updateModel(event, value || null);
if (this.focusedOptionIndex === value || this.modelValue === value) {
this.focusedOptionIndex = -1;
this.updateModel(event, null);
} else {
this.focusedOptionIndex = value;
this.updateModel(event, value || null);
}
},
updateModel(event, value) {
this.$emit('update:modelValue', value);

View file

@ -11,7 +11,7 @@ const classes = {
cancelItem: ({ instance }) => [
'p-rating-item p-rating-cancel-item',
{
'p-focus': instance.focusedOptionIndex === 0 && instance.isFocusVisibleItem
'p-focus-visible': instance.focusedOptionIndex === 0 && instance.isFocusVisibleItem
}
],
cancelIcon: 'p-rating-icon p-rating-cancel',
@ -19,7 +19,7 @@ const classes = {
'p-rating-item',
{
'p-rating-item-active': value <= props.modelValue,
'p-focus': value === instance.focusedOptionIndex && instance.isFocusVisibleItem
'p-focus-visible': value === instance.focusedOptionIndex && instance.isFocusVisibleItem
}
],
onIcon: 'p-rating-icon',