Skip to content
Open
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
18 changes: 9 additions & 9 deletions packages/vue-vuetify/src/controls/NumberControlRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ const controlRenderer = defineComponent({
const options: any = this.appliedOptions;
return options.step ?? 0.1;
},
precision(): number | undefined {
if (!this.step || Number.isInteger(this.step)) return undefined;
// Handle scientific notation and float imprecision
const stepStr = this.step.toString();
if (stepStr.indexOf('e-') > -1) {
// Handle cases like 1e-3
return parseInt(stepStr.split('e-')[1], 10);
precision(): number | null {
const options: any = this.appliedOptions;

// If precision is explicitly configured in the UI Schema options, respect it
if (options.precision !== undefined && options.precision !== null) {
return Number(options.precision);
}
const fraction = stepStr.split('.')[1];
return fraction ? fraction.length : undefined;

// Return null (not undefined) to allow Vuetify to accept any precision by default
return null;
},
value(): number | null | undefined {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,35 @@ describe('NumberControlRenderer.vue', () => {
expect(wrapper.html()).toMatchSnapshot();
});
});

import { VNumberInput } from 'vuetify/components';

describe('NumberControlRenderer precision logic', () => {
const renderers = [numberControlRendererEntry];
const schema = { type: 'number' };

beforeEach(() => {
clearAllIds();
});

it('allows unlimited precision by default (passes null to v-number-input)', () => {
const uischema = { type: 'Control', scope: '#' };
const wrapper = mountJsonForms(1.23456, schema, renderers, uischema);

const numberInput = wrapper.findComponent(VNumberInput);
// Vuetify requires null to remove precision limits
expect(numberInput.props('precision')).toBeNull();
});

it('respects explicitly configured precision via UI schema options', () => {
const uischema = {
type: 'Control',
scope: '#',
options: { precision: 3 }
};
const wrapper = mountJsonForms(1.23456, schema, renderers, uischema);

const numberInput = wrapper.findComponent(VNumberInput);
expect(numberInput.props('precision')).toBe(3);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports[`NumberControlRenderer.vue > should render component and match snapshot
</label><label class="v-label v-field-label" id="#6-input-label" aria-hidden="true">
<!---->My Number
</label>
<!----><input placeholder="number placeholder" size="1" type="text" aria-labelledby="#6-input-label" id="#6-input" aria-describedby="#6-input-messages" inputmode="decimal" class="v-field__input" value="1.0">
<!----><input placeholder="number placeholder" size="1" type="text" aria-labelledby="#6-input-label" id="#6-input" aria-describedby="#6-input-messages" inputmode="decimal" class="v-field__input" value="1">
<!---->
</div>
<transition-stub name="expand-x-transition" appear="false" persisted="false" css="true">
Expand Down