Preço certo, prazo antigo: como conferir as transições de uma proposta em HTML
Uma proposta interativa pode mostrar o preço certo e, ao mesmo tempo, manter o prazo da opção anterior. É fácil não perceber isso quando cada botão é conferido separadamente. Ao organizar um exemplo pequeno em HTML e JavaScript, o critério foi fazer preço, prazo e entregáveis saírem da mesma combinação de dados. São dois pacotes e duas revisões, com valores fictícios. Primeiro, saber de onde vem…
Proposals can display the correct price while maintaining the duration of the previous option. It's easy to miss this when each button is checked individually. To organize a small example in HTML and JavaScript, the goal was to ensure price, deadline, and deliverables emerged from the same data combination. There are two packages and two reviews, with fictional values.
First, it's important to know where each response comes from. The state holds the choices, not the result: let revision = first ; let plan = essential ; A table contains the four combinations. This excerpt uses USD figures only to illustrate the model, without currency conversion: const proposals = { first : { essential : { price : 4800 , weeks : 3 }, complete : { price : 7200 , weeks : 4 } }, revised : { essential : { price : 5400 , weeks : 4 }, complete : { price : 8100 , weeks : 5 } } }; The current record is proposals[revision][plan] .
There's no extra variable for price or deadline. So, fewer values need to be maintained in agreement. The event triggers; the rendering updates. Instead of each button updating a piece of the page, the events change a choice and call the same render() function. In the full example, this function updates the summary, rebuilds the list of deliverables, and adjusts aria-pressed for the two groups of buttons.
Text enters with textContent, not being interpreted as HTML. This also avoids odd behavior: switching the review doesn't revert the package to basic. This choice makes comparison easier to follow. If a package isn't available in a future revision, the interface needs to handle and explain this case. Checking four results and walking the path helps find an incorrect data point.
But the interface keeps memory between clicks: some elements might retain the content of the previous selection. Therefore, it's worth walking through Complete → Revised → Basic → Initial without reloading the page. At each step, verify: if the price and deadline correspond to the same combination; if the deliverables list was updated; if the chosen package was kept when switching the review; if the selected package was correctly maintained when switching the review.
Keyboard input also needs to enter the check. Controls use button elements. Tab changes focus; Enter and Space activate the button. aria-pressed exposes the selection. The summary uses aria-live= polite and aria-atomic= true , making the complete update available to assistive technologies. It's still necessary to check the behavior in the screen readers used by the audience; these attributes alone don't guarantee a good experience.
The preview isn't a publication. The two reviews are already in the file. The button toggles what appears, without saving or updating the hosted page. That's why "preview of the revision" describes the action better. To update the public content, the altered file needs to be sent and the address that will be shared needs to be checked.
The example was kept small because it has a limited task: compare scope without separating price, deadline, and deliverables. The interesting part is to verify if this promise still holds after many clicks. The original article in English provides the complete HTML and JavaScript for reproducing the example. Here, the focus was on the reasoning behind verifying the transitions. Do you usually test the states separately first or start with the paths users might take?
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.