Refactor DropdownButton API for more robust event handling#1062
Refactor DropdownButton API for more robust event handling#1062
Conversation
Refactor the DropdownButton component to move away from a fragile, label-based event emission to a more robust, ID-based approach. - Update `items` prop to expect objects with `id`, `label`, and `icon`. - Modify `action-click` event to emit only the `id` of the selected item. - Update documentation and examples to reflect the new API. - Add unit tests for the updated component behavior. Co-authored-by: geidsonc <9142676+geidsonc@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Refactor DropdownButton component to use a more robust, ID-based API for items and events, suitable for the next major version. Also, fix a non-deterministic CI failure in DateInput tests by mocking the system time. DropdownButton changes: - Update `items` prop to expect objects with `id`, `label`, and `icon`. - Modify `action-click` event to emit only the `id` of the selected item. - Update documentation and examples to reflect the new API. - Add unit tests for the updated component behavior in `src/tests/DropdownButton.spec.ts`. CI fix: - Fix non-deterministic snapshot mismatch in `src/tests/DateInput.spec.js` by using `vi.useFakeTimers()` and `vi.setSystemTime()` to fix the date to 2026-02-01. Co-authored-by: geidsonc <9142676+geidsonc@users.noreply.github.com>
Greptile SummaryEste PR refatora a API do componente Mudanças principais:
Problema identificado:
Esta é uma breaking change planejada para a próxima versão major da biblioteca. Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| src/components/DropdownButton.vue | Refatoração da API para emitir IDs ao invés de arrays [nome, índice]; potencial bug se items não tiverem id |
| src/tests/DropdownButton.spec.ts | Novo teste verifica emissão do evento com id; falta cobertura de casos extremos |
| docs/components/display/dropdown-button.md | Documentação atualizada corretamente com a nova estrutura da API (id, label, icon) |
Sequence Diagram
sequenceDiagram
participant User
participant DropdownButton
participant Parent
User->>DropdownButton: Clica no botão
DropdownButton->>DropdownButton: activeSelection()
DropdownButton->>Parent: emit('button-click', true)
DropdownButton->>DropdownButton: isActive = true
User->>DropdownButton: Clica em uma opção
DropdownButton->>DropdownButton: handleOptionClick(item)
DropdownButton->>Parent: emit('action-click', item.id)
Note right of Parent: Antes: emit('action-click', [name, index])<br/>Agora: emit('action-click', item.id)
DropdownButton->>DropdownButton: isActive = false
Last reviewed commit: f540557
| function handleOptionClick(item) { | ||
| isActive.value = !isActive.value; | ||
| emits('action-click', [actionName, index]); | ||
| emits('action-click', item.id); | ||
| } |
There was a problem hiding this comment.
Se um item não tiver id, isso emitirá undefined. O template usa item.id || index como fallback na key (linha 33), mas aqui não há fallback.
| function handleOptionClick(item) { | |
| isActive.value = !isActive.value; | |
| emits('action-click', [actionName, index]); | |
| emits('action-click', item.id); | |
| } | |
| function handleOptionClick(item, index) { | |
| isActive.value = !isActive.value; | |
| emits('action-click', item.id || index); | |
| } |
Ou então, adicione validação na prop items para garantir que todos os itens tenham id.
The
DropdownButtoncomponent's API was refactored to improve its robustness and maintainability.Changes:
itemsprop documentation to specify the new required object structure (id,label,icon).item.labelfor rendering the option text anditem.id(falling back toindex) for the:key.handleOptionClickmethod to emit theidof the selected item instead of a[name, index]array.docs/components/display/dropdown-button.mdfile with a new example that follows the improved API structure.src/tests/DropdownButton.spec.tsto verify the new event emission logic and component behavior.This change is intended for the next major version of the library as it introduces a breaking change to the event payload.
Fixes #944
PR created automatically by Jules for task 7622798767401053030 started by @geidsonc