@v-c/input-number 1.1.2 → 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);
@@ -335,7 +336,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
335
336
  if (props.formatter) restoreCursor();
336
337
  }, { flush: "post" });
337
338
  return () => {
338
- 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;
339
340
  const mergedPrefixCls = prefixCls || defaults.prefixCls;
340
341
  const { class: className, style, ...restAttrs } = attrs;
341
342
  const mergedClassName = props.className || className;
@@ -348,13 +349,14 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
348
349
  const suffixNode = slots.suffix?.() ?? props.suffix;
349
350
  const upNode = slots.upHandler?.() ?? props.upHandler;
350
351
  const downNode = slots.downHandler?.() ?? props.downHandler;
351
- const clearConfig = allowClear && typeof allowClear === "object" ? allowClear : { disabled: allowClear !== true };
352
+ const clearConfig = allowClearConfig.value;
352
353
  const showClear = !disabled && !readOnly && clearConfig.disabled !== true && String(inputValue.value).length > 0;
353
354
  const hasSuffix = isVueRenderable(suffixNode);
354
355
  const clearIconCls = `${mergedPrefixCls}-clear-icon`;
355
- const clearNode = allowClear && createVNode("button", {
356
+ const clearNode = !clearConfig.disabled && createVNode("button", {
356
357
  "type": "button",
357
358
  "aria-label": clearConfig.label ?? "Clear",
359
+ "tabindex": clearConfig.tabIndex,
358
360
  "disabled": !showClear,
359
361
  "class": clsx(clearIconCls, {
360
362
  [`${clearIconCls}-hidden`]: !showClear,
@@ -481,7 +483,7 @@ var InputNumber = /* @__PURE__ */ defineComponent((props, { attrs, slots, expose
481
483
  "onCompositionend": onCompositionEnd,
482
484
  "onBeforeinput": onBeforeInput
483
485
  }, inputAttrs), null),
484
- (allowClear || hasSuffix) && createVNode("div", {
486
+ (!clearConfig.disabled || hasSuffix) && createVNode("div", {
485
487
  "class": clsx(`${mergedPrefixCls}-suffix`, classNames?.suffix),
486
488
  "style": styles?.suffix
487
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.2",
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.2.0",
34
- "@v-c/util": "^1.3.2",
35
- "@v-c/mini-decimal": "^1.0.2"
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",