Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Forms): add missing support for defaultValue for Field.Slider #4394

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tujoworker marked this conversation as resolved.
Show resolved Hide resolved
)
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
Loading