Skip to content

Commit

Permalink
Merge branch 'main' into fix-NBadge-bug-in-NButton
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Sep 18, 2021
2 parents aec00ec + f5ef4ce commit fb7b864
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- `n-layout-sider` add `collapsed-trigger-style` prop.
- `n-menu` add `accordion` prop , closes [#917](https://github.com/TuSimple/naive-ui/issues/917).
- `n-input-number` add `readonly` prop , closes [#1198](https://github.com/TuSimple/naive-ui/issues/1198).

### Fixes

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- `n-layout-sider` 新增 `collapsed-trigger-style` 属性
- `n-menu` 添加 `accordion` 属性,关闭 [#917](https://github.com/TuSimple/naive-ui/issues/917)
- `n-input-number` 新增 `readonly` 属性,关闭 [#1198](https://github.com/TuSimple/naive-ui/issues/1198)

### Fixes

Expand Down
20 changes: 14 additions & 6 deletions src/input-number/src/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const inputNumberProps = {
type: Boolean,
default: true
},
readonly: Boolean,
clearable: Boolean,
'onUpdate:value': [Function, Array] as PropType<MaybeArray<OnUpdateValue>>,
onUpdateValue: [Function, Array] as PropType<MaybeArray<OnUpdateValue>>,
Expand Down Expand Up @@ -95,10 +96,12 @@ export default defineComponent({
)
const displayedValueRef = ref('')
const getMaxPrecision = (currentValue: number): number => {
const precisions = [props.min, props.max, props.step, currentValue].map((item) => {
const fraction = String(item).split('.')[1]
return fraction ? fraction.length : 0
})
const precisions = [props.min, props.max, props.step, currentValue].map(
(item) => {
const fraction = String(item).split('.')[1]
return fraction ? fraction.length : 0
}
)
return Math.max(...precisions)
}
const mergedPlaceholderRef = useMemo(() => {
Expand Down Expand Up @@ -385,6 +388,7 @@ export default defineComponent({
size={this.mergedSize}
placeholder={this.mergedPlaceholder}
disabled={this.mergedDisabled}
readonly={this.readonly as any}
textDecoration={
this.displayedValueInvalid ? 'line-through' : undefined
}
Expand All @@ -407,7 +411,9 @@ export default defineComponent({
),
<NButton
text
disabled={!this.minusable || this.mergedDisabled}
disabled={
!this.minusable || this.mergedDisabled || this.readonly
}
focusable={false}
builtinThemeOverrides={this.buttonThemeOverrides}
onClick={this.handleMinusClick}
Expand All @@ -425,7 +431,9 @@ export default defineComponent({
</NButton>,
<NButton
text
disabled={!this.addable || this.mergedDisabled}
disabled={
!this.addable || this.mergedDisabled || this.readonly
}
focusable={false}
builtinThemeOverrides={this.buttonThemeOverrides}
onClick={this.handleAddClick}
Expand Down

0 comments on commit fb7b864

Please sign in to comment.