Skip to content

Commit

Permalink
fix: NumberInput v-model
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWaldschmidt committed Feb 15, 2024
1 parent f533c23 commit f7aa57e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v2.0.14

- Fix `v-model` on `NumberInput`

## v2.0.13

- Fix `maxFractionDigits` prop on `Number Input`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lob/ui-components",
"version": "2.0.13",
"version": "2.0.14",
"engines": {
"node": ">=20.2.0",
"npm": ">=10.2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/components/NumberInput/NumberInput.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Canvas, ArgTypes, PRIMARY_STORY } from '@storybook/addon-docs';
import { Primary, Currency } from './NumberInput.stories';

# Input Number
# Number Input

## Primary

Expand Down
2 changes: 1 addition & 1 deletion src/components/NumberInput/NumberInput.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mdx from './NumberInput.mdx';
import { NumberInputMode } from './constants';

export default {
title: 'Components/Input Number',
title: 'Components/Number Input',
component: NumberInput,
parameters: {
docs: {
Expand Down
12 changes: 8 additions & 4 deletions src/components/NumberInput/NumberInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div
class="uic-input-number-container"
data-testid="uic-input-number-container"
v-bind="containerProps"
>
<Label
:label-for="id"
Expand All @@ -11,6 +12,7 @@
data-testid="uic-input-number-label"
/>
<InputNumber
data-testid="testing-number"
:currency="currency"
:disabled="disabled"
:input-class="[
Expand All @@ -33,7 +35,8 @@
unstyled
@blur="emits('blur')"
@focus="emits('focus')"
@input="(e) => emits('update:modelValue', e.value as number)"
@update:modelValue="emits('update:modelValue', $event)"
@input="emits('update:modelValue', $event.value as number)"
/>
<!-- The PrimeVue number input does not have helper text, I copied this from the PrimeVue text input. -->
<small
Expand All @@ -58,7 +61,7 @@ export default {
</script>
<script setup lang="ts">
import InputNumber, { InputNumberProps } from 'primevue/inputnumber';
import { InputHTMLAttributes, computed, useAttrs } from 'vue';
import { HTMLAttributes, InputHTMLAttributes, computed, useAttrs } from 'vue';
import Label from '../Label/Label.vue';
import { NumberInputMode } from './constants';
Expand All @@ -67,6 +70,7 @@ const attrs = useAttrs();
const props = withDefaults(
defineProps<{
containerProps?: HTMLAttributes;
disabled?: InputNumberProps['disabled'];
error?: boolean;
helperText?: string;
Expand All @@ -86,6 +90,7 @@ const props = withDefaults(
success?: boolean;
}>(),
{
containerProps: undefined,
disabled: false,
error: false,
helperText: undefined,
Expand Down Expand Up @@ -130,7 +135,7 @@ const currency = computed(() =>
}
.uic-input-number {
@apply px-4 py-3;
@apply w-full px-4 py-3;
@apply text-sm text-gray-800;
@apply bg-white;
@apply border border-gray-200 rounded;
Expand Down Expand Up @@ -190,4 +195,3 @@ const currency = computed(() =>
}
}
</style>
NumberInputModeNumberInputModeNumberInputModeNumberInputModeNumberInputModeNumberInputModeNumberInputModeNumberInputMode
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,40 @@ describe('NumberInput', () => {
expect(helperText.textContent).toContain(DEFAULT_PROPS.helperText);
});

it('updates', () => {
const { getByTestId } = render(NumberInput, {
props: { ...DEFAULT_PROPS, modelValue: 50 }
it('updates', async () => {
const { emitted, getByTestId } = render(NumberInput, {
props: { ...DEFAULT_PROPS }
});
const numberInput = getByTestId('uic-input-number');

expect(numberInput).toHaveValue('50');
fireEvent.update(numberInput, '123');
expect(numberInput).not.toHaveValue('123');
expect(numberInput).not.toHaveAttribute('aria-valuenow', '123');

await fireEvent.update(numberInput, '123');
await fireEvent.blur(numberInput);

expect(numberInput).toHaveValue('123');
expect(numberInput).toHaveAttribute('aria-valuenow', '123');
expect(emitted()).toHaveProperty('update:modelValue', [[123]]);
});

it('emits focus', () => {
it('emits focus', async () => {
const { getByTestId, emitted } = render(NumberInput, {
props: DEFAULT_PROPS
});
const numberInput = getByTestId('uic-input-number');

fireEvent.focus(numberInput);
await fireEvent.focus(numberInput);
expect(emitted()).toHaveProperty('focus');
});

it('emits blur', () => {
it('emits blur', async () => {
const { getByTestId, emitted } = render(NumberInput, {
props: DEFAULT_PROPS
});
const numberInput = getByTestId('uic-input-number');

fireEvent.blur(numberInput);
await fireEvent.blur(numberInput);
expect(emitted()).toHaveProperty('blur');
});
});

0 comments on commit f7aa57e

Please sign in to comment.