Modals & Modal Lifecycle

Modals & Modal Lifecycle

Complete reference for OffersDetailModal and SubscriptionProfileModal — open/close, animations, isClosing state, accessibility, and validation best practices

A practical guide to using modals correctly — from user flows to accessibility and preventing state bugs.

Covered Components

OffersDetailModal

Detailed comparison view for insurance plans. Used to compare multiple plans side‑by‑side and choose a plan without leaving the current page.

SubscriptionProfileModal

Profile edit modal used to update personal details (name, birthdate, address, email, phone). Opens from the subscription flow and supports field-specific edits.

Full Modal Lifecycle

Guidance on opening, closing, animations (including isClosing state), focus management, accessibility, validation, and edge cases.

Intro This page explains how to use the OffersDetailModal and SubscriptionProfileModal in real workflows. It focuses on modal lifecycle (open → visible → close with animations), managing an isClosing state to ensure smooth animated exits, accessibility responsibilities, and concrete guidance for validating user input before sending updates to the backend. Example flows include editing profile details and comparing offers.

Modal open / close lifecycle — step-by-step (general)

1

Step 1 — Trigger the modal

User activates a clear trigger: button, link, or an icon with an accessible label (e.g., “Edit”, “Compare offers”). The trigger must be obvious and reachable by keyboard and touch.

2

Step 2 — Modal becomes visible and receives focus

When the modal opens, move focus into the modal to the most important interactive element (first input, primary action, or modal title). Announce the modal to assistive tech with a clear title and role.

3

Step 3 — Modal interaction

While open, trap focus inside the modal so Tab/Shift+Tab cycle through modal controls only. Keep background content inert (not interactive) and dimmed visually.

4

Step 4 — Request to close

User initiates close via close button, backdrop click, or Escape key. At this point, start a close sequence rather than instantly removing UI.

5

Step 5 — Enter isClosing state and run exit animation

Set a short isClosing state to play the exit animation. During this time: disable inputs and actions inside the modal, keep focus inside the modal until animation completes, and show any “saving” indicator if the close was triggered by a submit.

6

Step 6 — Finalize close and return focus

After the animation finishes, remove the modal from view and return focus to the original trigger. Update the visible state of the page (e.g., updated profile fields or selected plan).

7

Step 7 — Cleanup

Clear any temporary state used by the modal (form fields, error messages, timers). If an operation was pending, display a confirmation or error message outside the modal as needed.

Keep animations short and meaningful

Use short animations (150–300ms) for open/close so users experience fluid transitions without delay. Respect users’ reduced-motion preferences and disable animations if requested.

Editing profile details — user flow (SubscriptionProfileModal)

1

Step 1 — Initiate edit from the profile card

User clicks the edit icon next to the field they want to change (name, birthdate, address, email or phone). The trigger should be labeled with the field it edits (e.g., “Edit name”).

2

Step 2 — Modal opens showing only relevant inputs

The modal shows only the inputs needed for that edit type (for clarity). The first input receives focus automatically for quick editing.

3

Step 3 — Validate input as the user types

Provide live validation feedback:

  • Required fields show an inline message when empty.
  • Email format is validated immediately.
  • Phone uses a simple format check and shows an example format.
  • Postal code and city are validated together when possible. Always show clear, friendly error messages and guidance to fix them.
4

Step 4 — Prevent submit until valid

Disable the submit button while validation errors exist. If certain checks are asynchronous (like an email uniqueness check), show a small inline spinner and block submission until the check completes.

5

Step 5 — Submit and show progress

When the user submits:

  • Disable form inputs and the submit action.
  • Show a spinner or “Saving…” state.
  • Play the modal close exit animation once the save succeeds (go into isClosing state).
6

Step 6 — Confirm update and close modal

After a successful update, close the modal with animation, return focus to the edit trigger, and show a persistent confirmation message (toast or inline banner) that the profile was updated.

7

Step 7 — Handle errors gracefully

If save fails:

  • Keep modal open and re-enable inputs.
  • Show a clear error message (why it failed and what to try).
  • Allow the user to retry or cancel.

Save locally while editing for good UX

If the user navigates away or accidentally closes the modal during typing, consider preserving their draft in temporary state so they don’t lose typed information.

Comparing offers — user flow (OffersDetailModal)

1

Step 1 — Open comparison from the offers list

User clicks “Compare levels” or similar. The modal opens centered and shows a side-by-side view of plans or coverage levels.

2

Step 2 — Provide contextual toggles

Include contextual toggles inside the modal (e.g., 100% santé vs classic) so users can change the comparison mode and see differences immediately.

3

Step 3 — Allow selection inside the modal

Users can select or highlight a preferred plan directly in the modal. Make the selection action prominent and reversible while the modal is open.

4

Step 4 — Confirm choice before leaving

If choosing the plan will change a critical application state, require explicit confirmation (a “Confirm selection” action). Avoid silently making permanent changes on modal close.

5

Step 5 — Close with animation and reflect selection

Once confirmed, close the modal with an exit animation, update the main UI to reflect the selected plan, and show a confirmation message.

6

Step 6 — Offer quick compare summary

Optionally display a brief summary on the main page after close (e.g., “You selected Plan X — click to view details”), so the user sees the result of their action at a glance.

Don’t mutate critical backend state without confirmation

Avoid automatically changing important data (selected plan, payment settings) just because a modal was closed. Require explicit confirmation inside the modal before triggering irreversible operations.

Managing isClosing state & animations — operational checklist

1

Step 1 — Always start a closed animation before removing UI

When closing is requested, switch to an isClosing state rather than immediately removing the modal. This lets the exit animation play and avoids abrupt UI jumps.

2

Step 2 — Disable interactions during isClosing

While isClosing is true, disable form inputs and action buttons to prevent double actions or weird state transitions.

3

Step 3 — Keep focus until animation completes

Do not move focus back to the trigger until after the exit animation finishes; otherwise keyboard users can end up navigating content incorrectly.

4

Step 4 — Respect reduced-motion preferences

If a user prefers reduced motion, skip or shorten animations and close immediately — still honour isClosing semantics nominally.

5

Step 5 — Use consistent animation timing

Pick a consistent exit duration (e.g., 200–260ms). Use the same duration across open/close to feel predictable. If an operation includes waiting for a backend response, show a saving indicator and only proceed to the close animation once the operation completes.

6

Step 6 — Handle abrupt interruptions

If the window loses focus or the browser navigates during isClosing, ensure cleanup still happens (temporary state cleared and user informed if an update was pending).

Accessibility checklist — make every modal usable

1

Step 1 — Descriptive title and role

Each modal should have a clear title. That title must be exposed to assistive technologies so users know the purpose of the dialog.

2

Step 2 — Keyboard navigation

Support keyboard-only operation: Tab/Shift+Tab cycle focus inside the modal, Enter activates primary actions, Escape closes the modal.

3

Step 3 — Focus management

When opening, focus the first meaningful control. When closing, return focus to the element that triggered the modal.

4

Step 4 — Visible and meaningful close affordance

Provide an obvious close button with an accessible label (e.g., “Close edit dialog”). Backdrop clicks should also close when appropriate, but never be the only way to close.

5

Step 5 — Announce state changes

When saving completes or fails, announce the result (toast or inline message) and ensure screen readers can detect it.

6

Step 6 — Respect reduced-motion

Honor the user’s OS-level reduced-motion preference by reducing or eliminating animations.

7

Step 7 — Contrast and tap targets

Ensure high color contrast for text and that interactive controls meet recommended touch target sizes.

Design modals for discoverability and recovery

Always provide an obvious way to cancel and a clear visual hierarchy between primary and secondary actions. If a user cancels, provide an easy path to recover any unsaved changes.

Validating user input before mutating backend state — best practice flow

1

Step 1 — Client-side validation first

Run basic checks locally (required fields, simple format checks for email/phone/postal code). Provide instant inline feedback so users fix issues before submit.

2

Step 2 — Asynchronous checks when required

For checks that require server knowledge (unique email, phone verification), run an asynchronous check and surface results inline before final submission.

3

Step 3 — Block submission on validation failure

Disable the submit action whenever validation fails or pending checks are running.

4

Step 4 — Provide clear success/failure messaging

On success, show a confirmation message after the modal closes. On failure, keep the modal open and display a helpful error with actions to retry or cancel.

5

Step 5 — Prevent double actions

Disable submit controls while a request is in-flight and show progress to avoid duplicate requests or duplicate state changes.

6

Step 6 — For critical changes, require explicit confirmation

When the change affects billing, plan selection, or irreversible state, require a second confirm step (e.g., “Confirm and update”) and give a brief summary of what will change.

7

Step 7 — Reconcile local UI and backend state

After the backend confirms success, update all visible UI in the page to match. If the backend returns an updated canonical value, use it; do not trust only the local input.

Use a focused modal that shows only the field to edit (small footprint). Best when you want a fast correction with minimal cognitive load. Validate inline. Close automatically on success with a short confirmation.

Use a larger modal with multiple inputs and a clear primary save action. Run comprehensive validation; consider a “Save” and a “Cancel” button. If changing many fields, consider a confirmation summary before final save.

Use a read-heavy layout showing side-by-side differences and toggles. Selection should be explicit and reversible until a final confirm action.

When changes are risky, require the user to confirm in the modal (or in a follow-up confirmation modal) before the system performs the change.

Before: naive modal behaviour

  • Immediate removal of modal on close (no animation).
  • Focus may jump unpredictably.
  • Background still interactive.
  • Validations are weak and user can submit invalid data.

After: robust modal lifecycle

  • Exit animation plays via isClosing state.
  • Focus trap and return to trigger.
  • Background inert while modal open.
  • Inline validation, async checks, and controlled submission with confirmations for critical changes.

Common mistakes to avoid

  • Closing the modal before a save completes (can cause lost updates).
  • Not disabling controls during an in-flight save (double-submit risk).
  • Not returning focus to the trigger after close (keyboard users are stranded).
  • Making destructive changes just because the modal closed — require explicit confirmation for irreversible state changes.

Frequently Asked Questions

Need a quick checklist to copy into your product specs?

A printable checklist for modal lifecycle, accessibility, animations, and validation best practices — ready to paste into design or QA docs.

Summary

  • Use isClosing to run exit animations and avoid abrupt UI changes.
  • Always validate user input before initiating backend changes; block submission on errors.
  • Respect accessibility: focus management, keyboard support, and reduced motion.
  • For offers comparison, require explicit confirmation to apply critical choices.
  • For profile edits, present only the needed fields, validate proactively, and surface clear success/failure messages.

If you want, I can create a one-page printable checklist or a ready-made QA script that your team can use to test modal behavior across devices.