Skip to content

fix: improve number input UX in config renderer#7153

Open
Reisenbug wants to merge 2 commits intoAstrBotDevs:masterfrom
Reisenbug:fix/number-input-ux
Open

fix: improve number input UX in config renderer#7153
Reisenbug wants to merge 2 commits intoAstrBotDevs:masterfrom
Reisenbug:fix/number-input-ux

Conversation

@Reisenbug
Copy link
Copy Markdown
Contributor

@Reisenbug Reisenbug commented Mar 29, 2026

数字输入框体验较差
原生上下箭头按钮基本无用;输入过程中(如 0.、-、1e)每次按键都会触发parseFloat 强制转换。总之就是怪怪的

Modifications / 改动点

ConfigItemRenderer.vue:将数字类型转换推迟到失焦(blur)时执行;用本地 numericTemp ref 在输入过程中实时同步slider;通过 CSS 隐藏原生数字输入框的上下箭头

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Improve numeric configuration input UX by deferring numeric parsing and syncing the slider with in-progress text input, while hiding native number input spin buttons.

Enhancements:

  • Defer conversion of text input to numeric values until the input field loses focus to avoid disruptive parsing during typing.
  • Keep the slider value in sync with the temporary numeric text input state for smoother interaction between the slider and text field.
  • Hide native number input spin buttons via CSS for a cleaner numeric input appearance.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Mar 29, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The global :deep(input[type='number']) CSS selectors will affect all number inputs in the scoped subtree; consider narrowing them to this component (e.g., .config-field input[type='number']) so other numeric fields aren’t unintentionally modified.
  • When modelValue is updated externally while the user is mid-edit (with numericTemp set), the input will keep showing the stale numericTemp; consider resetting or syncing numericTemp with modelValue via a watch to avoid stale UI state.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The global `:deep(input[type='number'])` CSS selectors will affect all number inputs in the scoped subtree; consider narrowing them to this component (e.g., `.config-field input[type='number']`) so other numeric fields aren’t unintentionally modified.
- When `modelValue` is updated externally while the user is mid-edit (with `numericTemp` set), the input will keep showing the stale `numericTemp`; consider resetting or syncing `numericTemp` with `modelValue` via a `watch` to avoid stale UI state.

## Individual Comments

### Comment 1
<location path="dashboard/src/components/shared/ConfigItemRenderer.vue" line_range="160-165" />
<code_context>
-        :model-value="modelValue"
-        @update:model-value="val => emitUpdate(toNumber(val))"
+        :model-value="numericTemp ?? modelValue"
+        @update:model-value="val => (numericTemp = val)"
+        @blur="e => { emitUpdate(toNumber(e.target.value)); numericTemp = null }"
         density="compact"
         variant="outlined"
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Using the event target’s value directly in the blur handler is a bit fragile; consider relying on the v-model value instead.

Since `@update:model-value` already syncs `numericTemp`, you can have blur use that reactive value instead of `e.target.value`, e.g. `@blur="() => { emitUpdate(toNumber(numericTemp)); numericTemp = null }"`. This removes the assumption about the DOM event’s shape and keeps a single reactive source of truth.

```suggestion
        :model-value="numericTemp ?? modelValue"
        @update:model-value="val => (numericTemp = val)"
        @blur="() => { emitUpdate(toNumber(numericTemp)); numericTemp = null }"
        density="compact"
        variant="outlined"
        class="config-field"
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a numericTemp ref to manage temporary states for numeric inputs in ConfigItemRenderer.vue, specifically for v-slider and v-text-field components. It also adds CSS to hide spin buttons on number inputs. Feedback indicates a potential bug where numericTemp persists after slider interaction, which could prevent external prop updates from being reflected in the UI. A suggestion was made to reset this state on the slider's @end event and to remove redundant toNumber() calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant