Skip to content

Commit

Permalink
fix #16, release v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
smastrom committed Jan 28, 2024
1 parent e1f7cf8 commit c0baf1b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,16 @@ function App() {
### :cyclone: Core
| :thinking: | Prop | Description | Type | Default | Required |
| ------------------- | --------------- | -------------------------------------------------------------------------- | ----------------------------------------------- | --------- | ------------------------------- |
| :green_circle: | `value` | An integer from 0 to `items`. It can be a float if `readOnly` is **true**. | number | undefined | :white_check_mark: |
| :large_blue_circle: | `onChange` | Setter or custom function to update the rating. | RatingChange | () => {} | Only if `readOnly` is **false** |
| :large_blue_circle: | `onHoverChange` | Callback to execute while navigating the rating items. | (hoveredValue: number) => void | () => {} | :x: |
| :green_circle: | `items` | Rating items to display. | 1 \| 2 \| 3 \| 4 \| 5 \| 6 \| 7 \| 8 \| 9 \| 10 | 5 | :x: |
| :green_circle: | `readOnly` | Whether to render an accessible image element or not. | boolean | false | :x: |
| :large_blue_circle: | `isDisabled` | Whether to disable the radio group or not. | boolean | false | :x: |
| :large_blue_circle: | `isRequired` | Whether users should be able to set rating to 0 or not. | boolean | false | :x: |
| :thinking: | Prop | Description | Type | Default | Required |
| ------------------- | ---------------- | ------------------------------------------------------------------------------ | ----------------------------------------------- | --------- | ------------------------------- |
| :green_circle: | `value` | An integer from 0 to `items`. It can be a float if `readOnly` is **true**. | number | undefined | :white_check_mark: |
| :large_blue_circle: | `onChange` | Setter or custom function to update the rating. | RatingChange | () => {} | Only if `readOnly` is **false** |
| :large_blue_circle: | `onHoverChange` | Callback to execute while navigating the rating items. | (hoveredValue: number) => void | () => {} | :x: |
| :green_circle: | `items` | Rating items to display. | 1 \| 2 \| 3 \| 4 \| 5 \| 6 \| 7 \| 8 \| 9 \| 10 | 5 | :x: |
| :green_circle: | `readOnly` | Whether to render an accessible image element or not. | boolean | false | :x: |
| :large_blue_circle: | `isDisabled` | Whether to disable the radio group or not. | boolean | false | :x: |
| :large_blue_circle: | `isRequired` | Whether users should be able to set rating to 0 or not. | boolean | false | :x: |
| :green_circle: | `preventDefault` | Whether or not to call `event.preventDefault` on click and Enter/Space select. | `click` \| `keydown` \| `all` \| `none` | `all` | :x: |
`ref`, `id`, `className`, `style`, `onBlur`, `onFocus` are also available.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@smastrom/react-rating",
"version": "1.4.0",
"version": "1.5.0",
"private": false,
"keywords": [
"react",
Expand Down
10 changes: 7 additions & 3 deletions src/Rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const Rating: typeof RatingComponent = forwardRef<HTMLDivElement, RatingP
onHoverChange = noop,
onFocus = noop,
onBlur = noop,
preventDefault = 'all',
isDisabled = false,
highlightOnlySelected = false,
orientation = OrientationProps.HORIZONTAL,
Expand Down Expand Up @@ -232,7 +233,9 @@ export const Rating: typeof RatingComponent = forwardRef<HTMLDivElement, RatingP
}

function handleStarClick(event: MouseEvent, clickedIndex: number) {
event.preventDefault()
if (preventDefault === 'all' || preventDefault === 'keydown') {
event.preventDefault()
}
event.stopPropagation()

if (!isRequired && activeStarIndex === clickedIndex) {
Expand Down Expand Up @@ -318,11 +321,12 @@ export const Rating: typeof RatingComponent = forwardRef<HTMLDivElement, RatingP

case 'Enter':
case 'Space':
event.preventDefault()
if (preventDefault === 'all' || preventDefault === 'click') {
event.preventDefault()
}
return onChange(isResetBtn ? 0 : childIndex + 1)
}

event.preventDefault()
event.stopPropagation()
}

Expand Down
2 changes: 2 additions & 0 deletions src/exportedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export type InputProps = {
visibleItemLabelIds?: string[]
/** Accessible label for the invisible reset radio. Effective if `isRequired` is set to **false**. */
resetLabel?: string
/** Whether or not to call event.preventDefault on click and Enter/Space select. */
preventDefault?: 'click' | 'keydown' | 'all' | 'none'
}

export type RatingProps = SharedProps & ReadOnlyProps & InputProps
Expand Down

0 comments on commit c0baf1b

Please sign in to comment.