Skip to content

Fix/contador de caracteres travado em zero#585

Open
robsonsobral wants to merge 2 commits intohomolfrom
fix/contador-de-caracteres-travado-em-zero
Open

Fix/contador de caracteres travado em zero#585
robsonsobral wants to merge 2 commits intohomolfrom
fix/contador-de-caracteres-travado-em-zero

Conversation

@robsonsobral
Copy link
Collaborator

@robsonsobral robsonsobral commented Feb 23, 2026

Eu não gostei do resultado. Para fazer o campo funcionar com e sem o <Field> em volta, é preciso de uma baita salada.

Summary by CodeRabbit

  • New Features

    • Text input component now supports multiple operational modes, including autonomous and v-model controlled input, with improved character counter functionality.
  • Bug Fixes

    • Fixed empty field value handling and automatic trimming of trailing whitespace on field blur.
  • Tests

    • Expanded test suite with comprehensive coverage for all input modes, character counter behavior, and field trimming scenarios.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

The PR refactors SmaeText.vue to support three modes: autonomous with internal useField, Field v-slot, and v-model mode. It adds local value tracking (valorLocal) and synchronization logic, changes the modelValue prop default to undefined, and reorganizes the test suite with helper functions and structured describe blocks for improved clarity.

Changes

Cohort / File(s) Summary
SmaeText Component Refactoring
frontend/src/components/camposDeFormulario/SmaeText/SmaeText.vue, SmaeTextProps.ts
Introduces multi-mode support (autonomous, Field v-slot, v-model) via runtime detection of onUpdate:modelValue. Adds valorLocal for autonomous mode tracking and valorAtual computed binding for mode-agnostic value access. Synchronizes local state with VeeValidate via watcher. Reworks emission logic with emitValueComTrim for trimming. Changes modelValue default from empty string to undefined.
SmaeText Test Suite Overhaul
SmaeText.spec.js
Complete test reorganization with montar() helper function for simplified component mounting. Adds lifecycle hooks (beforeEach/afterEach) for mock/DOM cleanup. Groups tests into structured describe blocks covering: default rendering, counter visibility, autonomous mode, v-model mode, null emission, and whitespace trimming. Expands coverage with explicit DOM attribute assertions.
Template Formatting Adjustments
CicloAtualizacaoModalEditar.vue
Minor non-functional formatting changes: multiline conditional expressions in valorInicialVariaveis and class attribute line breaks for readability. No behavioral changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • GustavoFSoares
  • Eduruiz

Poem

🐰 Hop along with modes so sweet,
SmaeText dances to each beat,
Local values, trim with care,
Tests now grouped with flair to spare,
Multi-mode support's the way!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix/contador de caracteres travado em zero' accurately describes the main issue being addressed: fixing a character counter stuck at zero. It is concise, specific, and reflects the primary objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/contador-de-caracteres-travado-em-zero

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/src/components/camposDeFormulario/SmaeText/SmaeText.vue (1)

76-126: ⚠️ Potential issue | 🔴 Critical

Fix v-model mode detection: use vnode.props instead of $attrs for declared emits.

In Vue 3, event listeners for declared emits (e.g., update:modelValue) are excluded from $attrs by design to distinguish component events from fallthrough attributes. Since this component declares defineEmits(['update:modelValue']), the check 'onUpdate:modelValue' in attrs will always be false, breaking the v-model/Field v-slot mode detection even when the listener is present.

The suggested fix using getCurrentInstance()?.vnode.props correctly accesses the listener before Vue filters it and is a practical solution commonly used for this pattern.

🔧 Suggested adjustment
-import { computed, ref, useAttrs, watch } from 'vue';
+import { computed, getCurrentInstance, ref, useAttrs, watch } from 'vue';

 const attrs = useAttrs();
-const modoVModel = computed(() => 'onUpdate:modelValue' in attrs);
+const instance = getCurrentInstance();
+const modoVModel = computed(() => {
+  const vnodeProps = instance?.vnode.props ?? {};
+  return 'onUpdate:modelValue' in vnodeProps;
+});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/components/camposDeFormulario/SmaeText/SmaeText.vue` around
lines 76 - 126, The v-model detection using useAttrs() is wrong because declared
emits are removed from $attrs; change the modoVModel computed to inspect
getCurrentInstance()?.vnode.props (checking for 'onUpdate:modelValue' or
equivalent listener keys) instead of attrs so the component correctly detects
v-model mode; update any references to modoVModel (the computed used to set
standalone in useField) to rely on this new check and ensure null-safe access to
vnode.props to avoid runtime errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@frontend/src/components/camposDeFormulario/SmaeText/SmaeText.vue`:
- Around line 76-126: The v-model detection using useAttrs() is wrong because
declared emits are removed from $attrs; change the modoVModel computed to
inspect getCurrentInstance()?.vnode.props (checking for 'onUpdate:modelValue' or
equivalent listener keys) instead of attrs so the component correctly detects
v-model mode; update any references to modoVModel (the computed used to set
standalone in useField) to rely on this new check and ensure null-safe access to
vnode.props to avoid runtime errors.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5acaff5 and 52ed637.

📒 Files selected for processing (4)
  • frontend/src/components/camposDeFormulario/SmaeText/SmaeText.spec.js
  • frontend/src/components/camposDeFormulario/SmaeText/SmaeText.vue
  • frontend/src/components/camposDeFormulario/SmaeText/SmaeTextProps.ts
  • frontend/src/views/variaveis/CicloAtualizacao/CicloAtualizacaoModalEditar.vue

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant