Practice ยท 1 of 2
Modal Lifecycle
Write createModal() that RETURNS an object with:
- open(trigger, root) โ marks the modal open, remembers trigger as the element to restore focus to later, stores root as the modal content, and returns "opened"
- close() โ marks it closed and returns "closed"; if it was not open, returns "already-closed"
- restoreFocus() โ returns and clears the remembered trigger (undefined if none)
- isOpen() โ boolean state
Opening twice without closing returns "already-open" and must NOT overwrite the remembered trigger.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Stateful Components โ Practice