@v-c/input-number 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { ValueType } from '@v-c/mini-decimal';
2
+ import { AllowClearConfig } from '@v-c/util';
2
3
  import { InputFocusOptions } from '@v-c/util/dist/Dom/focus';
3
4
  export type { ValueType };
4
5
  type SemanticName = 'root' | 'actions' | 'input' | 'action' | 'prefix' | 'suffix' | 'clear';
@@ -19,11 +20,7 @@ export interface InputNumberProps<T extends ValueType = ValueType> {
19
20
  readOnly?: boolean;
20
21
  prefix?: any;
21
22
  suffix?: any;
22
- allowClear?: boolean | {
23
- clearIcon?: any;
24
- disabled?: boolean;
25
- label?: string;
26
- };
23
+ allowClear?: boolean | AllowClearConfig;
27
24
  upHandler?: any;
28
25
  downHandler?: any;
29
26
  keyboard?: boolean;
@@ -4,7 +4,7 @@ import StepHandler_default from "./StepHandler.js";
4
4
  import { getDecupleSteps } from "./utils/numberUtil.js";
5
5
  import { computed, createVNode, defineComponent, isVNode, mergeDefaults, mergeProps, shallowRef, watch, watchEffect } from "vue";
6
6
  import getMiniDecimal, { getNumberPrecision, num2str, toFixed, validateNumber } from "@v-c/mini-decimal";
7
- import { clsx, isVueRenderable } from "@v-c/util";
7
+ import { clsx, isVueRenderable, useAllowClear } from "@v-c/util";
8
8
  import { triggerFocus } from "@v-c/util/dist/Dom/focus";
9
9
  import { KeyCodeStr } from "@v-c/util/dist/KeyCode";
10
10
  import omit from "@v-c/util/dist/omit";
@@ -44,6 +44,7 @@ function getDecimalIfValidate(value) {
44
44
  }
45
45
  var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose, emit }) => {
46
46
  const focus = shallowRef(false);
47
+ const allowClearConfig = useAllowClear(() => props.allowClear);
47
48
  const userTypingRef = shallowRef(false);
48
49
  const compositionRef = shallowRef(false);
49
50
  const shiftKeyRef = shallowRef(false);
@@ -266,14 +267,15 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
266
267
  }
267
268
  };
268
269
  watchEffect((onCleanup) => {
269
- if (props.changeOnWheel && focus.value && inputRef.value) {
270
+ const input = inputRef.value;
271
+ if (props.changeOnWheel && focus.value && input) {
270
272
  const onWheel = (event) => {
271
273
  onInternalWheel(event);
272
274
  event.preventDefault();
273
275
  };
274
- inputRef.value.addEventListener("wheel", onWheel, { passive: false });
276
+ input.addEventListener("wheel", onWheel, { passive: false });
275
277
  onCleanup(() => {
276
- inputRef.value?.removeEventListener("wheel", onWheel);
278
+ input.removeEventListener("wheel", onWheel);
277
279
  resetWheel();
278
280
  });
279
281
  }
@@ -334,7 +336,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
334
336
  if (props.formatter) restoreCursor();
335
337
  }, { flush: "post" });
336
338
  return () => {
337
- const { prefixCls = defaults.prefixCls, classNames, styles, step = defaults.step, disabled, readOnly, controls = defaults.controls, mode = defaults.mode, placeholder, allowClear } = props;
339
+ const { prefixCls = defaults.prefixCls, classNames, styles, step = defaults.step, disabled, readOnly, controls = defaults.controls, mode = defaults.mode, placeholder } = props;
338
340
  const mergedPrefixCls = prefixCls || defaults.prefixCls;
339
341
  const { class: className, style, ...restAttrs } = attrs;
340
342
  const mergedClassName = props.className || className;
@@ -347,13 +349,14 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
347
349
  const suffixNode = slots.suffix?.() ?? props.suffix;
348
350
  const upNode = slots.upHandler?.() ?? props.upHandler;
349
351
  const downNode = slots.downHandler?.() ?? props.downHandler;
350
- const clearConfig = allowClear && typeof allowClear === "object" ? allowClear : { disabled: allowClear !== true };
352
+ const clearConfig = allowClearConfig.value;
351
353
  const showClear = !disabled && !readOnly && clearConfig.disabled !== true && String(inputValue.value).length > 0;
352
354
  const hasSuffix = isVueRenderable(suffixNode);
353
355
  const clearIconCls = `${mergedPrefixCls}-clear-icon`;
354
- const clearNode = allowClear && createVNode("button", {
356
+ const clearNode = !clearConfig.disabled && createVNode("button", {
355
357
  "type": "button",
356
358
  "aria-label": clearConfig.label ?? "Clear",
359
+ "tabindex": clearConfig.tabIndex,
357
360
  "disabled": !showClear,
358
361
  "class": clsx(clearIconCls, {
359
362
  [`${clearIconCls}-hidden`]: !showClear,
@@ -480,7 +483,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
480
483
  "onCompositionend": onCompositionEnd,
481
484
  "onBeforeinput": onBeforeInput
482
485
  }, inputAttrs), null),
483
- (allowClear || hasSuffix) && createVNode("div", {
486
+ (!clearConfig.disabled || hasSuffix) && createVNode("div", {
484
487
  "class": clsx(`${mergedPrefixCls}-suffix`, classNames?.suffix),
485
488
  "style": styles?.suffix
486
489
  }, [clearNode, suffixNode]),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/input-number",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.2.0",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/antdv-next/vue-components/tree/next/packages/input-number",
@@ -30,9 +30,9 @@
30
30
  "vue": "^3.0.0"
31
31
  },
32
32
  "dependencies": {
33
- "@v-c/input": "^1.1.2",
34
- "@v-c/mini-decimal": "^1.0.1",
35
- "@v-c/util": "^1.3.0"
33
+ "@v-c/input": "^1.3.0",
34
+ "@v-c/mini-decimal": "^1.0.2",
35
+ "@v-c/util": "^1.4.0"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "vite build",