Skip to content

Commit

Permalink
feat(Forms): add missing support for defaultValue for Field.Slider (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker authored Dec 13, 2024
1 parent ad35e67 commit 701ab66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ function SliderComponent(props: Props) {
[getSourceValue]
)

const value = getValues(props.paths ?? props.path ?? props.value)
const value = getValues(
props.paths ?? props.path ?? props.value ?? props.defaultValue
)
const preparedProps = {
...props,
step: getSourceValue(props.step),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const SliderFieldProperties: PropertiesTableProps = {
paths: {
doc: 'Define an array with JSON Pointer paths for multiple thumb buttons.',
type: 'Array<string>',
status: 'required',
status: 'optional',
},
min: SliderProperties.min,
max: SliderProperties.max,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ describe('Field.Slider', () => {
expect(parseFloat(getButtonHelper().value)).toBe(value + 10)
})

it('with "defaultValue"', () => {
const value = 70

render(
<Form.Handler>
<Field.Slider defaultValue={value} />
</Form.Handler>
)

fireEvent.submit(document.querySelector('form'))

expect(parseFloat(getButtonHelper().value)).toBe(value)
})

it('with "path"', () => {
render(
<Form.Handler data={{ myValue: 30 }}>
Expand Down

0 comments on commit 701ab66

Please sign in to comment.