Skip to content

Commit

Permalink
feat: support clearable option
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqing committed Aug 14, 2023
1 parent 54e2377 commit 659b790
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/Starscore.ts
Expand Up @@ -21,6 +21,7 @@ class Starscore implements StarscoreInstance {
disabledColor: '#c8c9cc',
icon: '',
voidIcon: '',
clearable: true,
readonly: false,
disabled: false,
allowHalf: false,
Expand Down Expand Up @@ -108,7 +109,10 @@ class Starscore implements StarscoreInstance {
if (scoreElement) {
const scoreValue = Number(scoreElement.dataset.score)

this.setValue(scoreValue)
const value =
this.options.clearable && this.value === scoreValue ? 0 : scoreValue

this.setValue(value)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/interfaces/core.ts
Expand Up @@ -16,6 +16,7 @@ export interface StarscoreOptions {
icon?: string
voidIcon?: string
allowHalf?: boolean
clearable?: boolean
readonly?: boolean
disabled?: boolean
scoreDetails?: StarscoreDetail[] | StarscoreDetailFn
Expand Down

0 comments on commit 659b790

Please sign in to comment.