fix: improve number input UX in config renderer#7153
Open
Reisenbug wants to merge 2 commits intoAstrBotDevs:masterfrom
Open
fix: improve number input UX in config renderer#7153Reisenbug wants to merge 2 commits intoAstrBotDevs:masterfrom
Reisenbug wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
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
modelValueis updated externally while the user is mid-edit (withnumericTempset), the input will keep showing the stalenumericTemp; consider resetting or syncingnumericTempwithmodelValuevia awatchto 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
数字输入框体验较差
原生上下箭头按钮基本无用;输入过程中(如 0.、-、1e)每次按键都会触发parseFloat 强制转换。总之就是怪怪的
Modifications / 改动点
ConfigItemRenderer.vue:将数字类型转换推迟到失焦(blur)时执行;用本地 numericTemp ref 在输入过程中实时同步slider;通过 CSS 隐藏原生数字输入框的上下箭头
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.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.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: