Guest Mode:

BCA Student Stories & UpdatesLive

You
Your StorySign in & share
Er. Manoj Kumar
D5
Er. ManojActive nowPages
Day 35Advanced JavaScript & Browser APIs2.5 Hours Practical
Push to GitHub to Complete

Dynamic Modal Dialogs, Overlay Mechanics & Keyboard Accessibility

Modal dialogs are essential UI components for confirmation prompts, authentication gates, image lightboxes, and detail drawers. Crafting professional modals requires careful orchestration of CSS overlays, body scroll prevention, event propagation handling, and keyboard accessibility (ESC key dismissal).

Interactive Learning Roadmap

Day 35 Step-by-Step Practical Flow

🎯1. What You Will Learn Today

✔Design full-screen backdrop overlays with CSS fixed positioning and backdrop-filter blur.
✔Control modal visibility via JavaScript classes (is-open, active) and manage document body scroll locks.
✔Implement multi-layered dismissal: Close Button click, Backdrop overlay click, and Escape key press.
✔Trap keyboard focus and prevent event propagation bugs using event.stopPropagation().
✔Build reusable modal dialog components that accept dynamic titles, content, and callback actions.
Day 35 MasterclassAdvanced JavaScript & Browser APIs

Dynamic Modal Dialogs, Overlay Mechanics & Keyboard Accessibility — Comprehensive Practical Guide

Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.

Real-World Purpose Aur Zaroorat

Modal dialogs are essential UI components for confirmation prompts, authentication gates, image lightboxes, and detail drawers. Crafting professional modals requires careful orchestration of CSS overlays, body scroll prevention, event propagation handling, and keyboard accessibility (ESC key dismissal).

Overlay Architecture: Use position: fixed; inset: 0; z-index: 9999 with a semi-transparent black background (#00000099).
Body Scroll Lock: When the modal opens, set document.body.style.overflow = "hidden" to prevent background scrolling.
stopPropagation(): Backdrop click handlers must avoid closing when users click inside the modal content box.
Keyboard Accessibility: Listen on window for keydown events and dismiss when e.key === "Escape".
ARIA Attributes: Add aria-modal="true" and role="dialog" for screen reader accessibility compliance.
Dimaag Mein Bithane Ka Model

"Think of a modal dialog like a spotlight on a theatre stage: the rest of the stage is darkened and muted, directing 100% of the audience attention onto the central scene until the spotlight is turned off."

💡 Pro Tip: Code ko ratta mat maaro; imagine karo ki browser har tag ko visually kaise draw karta hai.

👨‍🏫3. Teacher Demonstration Code

Notice how click propagation is controlled and the Escape key listener is registered cleanly.

Accessible Modal Dialog Architecture with ESC & Backdrop Dismissalhtml
<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: 'Segoe UI', sans-serif; background: #060c18; color: #fff; padding: 24px; }
    .backdrop {
      position: fixed; inset: 0; background: rgba(0,0,0,0.75);
      backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center;
      z-index: 1000;
    }
    .backdrop.active { display: flex; }
    .modal-box {
      background: #0c1328; border: 1px solid #1e293b; border-radius: 14px;
      padding: 24px; max-width: 440px; width: 90%; box-shadow: 0 20px 40px rgba(0,0,0,0.6);
      transform: scale(0.95); transition: transform 0.2s;
    }
    .backdrop.active .modal-box { transform: scale(1); }
    .modal-header { display: flex; justify-content: space-between; align-items: center; }
    .close-btn { background: none; border: none; color: #94a3b8; font-size: 20px; cursor: pointer; }
    .modal-footer { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }
    button.primary { background: #2563eb; color: #fff; border: none; padding: 10px 16px; border-radius: 6px; cursor: pointer; }
  </style>
</head>
<body>
  <h2>🎓 BCA Portal Confirmation Engine</h2>
  <button class="primary" id="openModalBtn">Open Submission Modal</button>

  <div class="backdrop" id="modalBackdrop">
    <div class="modal-box" id="modalContent">
      <div class="modal-header">
        <h3>Confirm Practical Submission</h3>
        <button class="close-btn" id="closeBtn">✕</button>
      </div>
      <p style="color:#94a3b8;margin-top:12px;">Are you ready to submit Day 35 practical tasks to the evaluation studio? This action will sync with your profile.</p>
      <div class="modal-footer">
        <button id="cancelBtn" style="background:#334155;color:#fff;border:none;padding:10px 16px;border-radius:6px;cursor:pointer;">Cancel</button>
        <button class="primary" id="confirmBtn">Confirm & Submit</button>
      </div>
    </div>
  </div>

  <script>
    const backdrop = document.getElementById("modalBackdrop");
    const modalContent = document.getElementById("modalContent");
    const openBtn = document.getElementById("openModalBtn");
    const closeBtn = document.getElementById("closeBtn");
    const cancelBtn = document.getElementById("cancelBtn");

    function openModal() {
      backdrop.classList.add("active");
      document.body.style.overflow = "hidden"; // Prevent body scroll
    }

    function closeModal() {
      backdrop.classList.remove("active");
      document.body.style.overflow = ""; // Restore body scroll
    }

    openBtn.addEventListener("click", openModal);
    closeBtn.addEventListener("click", closeModal);
    cancelBtn.addEventListener("click", closeModal);

    // Close on backdrop click (outside modal content)
    backdrop.addEventListener("click", (e) => {
      if (e.target === backdrop) closeModal();
    });

    // Close on ESC key press
    window.addEventListener("keydown", (e) => {
      if (e.key === "Escape" && backdrop.classList.contains("active")) {
        closeModal();
      }
    });
  </script>
</body>
</html>

2. Hands-On Practical Lab: Follow Instructions in VS Code

Code like a professional software engineer! Follow the step-by-step instructions below in Visual Studio Code (VS Code) on your PC, test your output locally, and push to GitHub.

2 Coding Tasks
Interactive Coding TestAuto-Evaluates as you type

Day 35 Practical Task Test Studio

Test Score:0 / 2 Passed
1. Practical Task Specifications & Live Test Checklist:Type code below to pass tests
Task 1Implement Escape Key Listener

Listen for keydown events on window and invoke closeModal() if e.key === "Escape".

⏳ WAITING
Task 2Lock Body Scrolling on Modal Open

Set document.body.style.overflow = "hidden" when opening the modal and restore to "" on close.

⏳ WAITING
2. Type HTML & CSS Code:index.html
index.html
⚡ Real-Time Testing Active
Tab inserts 2 spaces • Live DOM refresh392 chars
Live Browser Output:
🔒 http://localhost:5500/index.html
Live
Renders live HTML & CSS typed on the left.
Interactive Bug Detective

Backdrop Click Accidentally Triggered Inside Modal Content Bug

Tap or click on the exact line below that contains the error:

Click any code line
⚠️ Broken Code Inspector
Tap buggy line
1
const backdrop = document.querySelector(".backdrop");
2
const box = document.querySelector(".modal-box");
3
4
// ❌ Bug: Clicking anywhere inside the modal box triggers backdrop click listener!
5
backdrop.addEventListener("click", () => {
6
closeModal();
7
});
Stuck? Need a detective clue before checking the solution?

Senior Developer Forensic Analysis:

Because events bubble up from child elements to parent elements, clicking inside the modal box causes the click event to bubble up to the backdrop, immediately closing the modal whenever users try to interact with it.

Golden Rule: Always validate code syntax and security attributes before pushing to GitHub!

📝Independent Practice: Assignment

📄 index.html

BCA Student Profile Inspector & Detail View Modal

  • •Create a student list with 4 student cards displaying Name, Roll Number, and View Details buttons.
  • •Clicking View Details opens a centered modal with animated scale transition displaying complete profile information.
  • •Ensure the modal closes via: ✕ button, Cancel button, Backdrop click, and Escape key.
  • •Prevent background body scrolling when modal is open.
Submission Evaluation Criteria: Push index.html and styles.css to your GitHub repository under day-35.
Exact Assignment Solution Code: index.html

Open Visual Studio Code on your PC (code .), create index.html, paste this complete step-by-step verified code, test in your browser, and push to your GitHub repo:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>BCA Day 35 - Profile Modal</title>
  <style>
    body { font-family: 'Segoe UI', sans-serif; background: #060c18; color: #fff; padding: 24px; }
    .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; max-width: 680px; margin: auto; }
    .card { background: #0c1328; border: 1px solid #1e293b; padding: 16px; border-radius: 10px; text-align: center; }
    button { padding: 8px 14px; background: #2563eb; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; margin-top: 10px; }
    .backdrop {
      position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(4px);
      display: none; align-items: center; justify-content: center; z-index: 1000;
    }
    .backdrop.active { display: flex; }
    .modal { background: #0c1328; border: 1px solid #334155; padding: 24px; border-radius: 12px; width: 90%; max-width: 400px; }
  </style>
</head>
<body>
  <div class="grid">
    <div class="card">
      <h3>Amit Verma</h3>
      <p style="color:#94a3b8;">Roll: BCA-2401</p>
      <button onclick="showDetails('Amit Verma', 'BCA-2401', 'Web Development Track', '94% Attendance')">View Profile</button>
    </div>
    <div class="card">
      <h3>Sneha Gupta</h3>
      <p style="color:#94a3b8;">Roll: BCA-2402</p>
      <button onclick="showDetails('Sneha Gupta', 'BCA-2402', 'Data Analytics Track', '98% Attendance')">View Profile</button>
    </div>
  </div>

  <div class="backdrop" id="modalBackdrop">
    <div class="modal" id="modalBox">
      <h3 id="modalName">Student Details</h3>
      <p id="modalRoll" style="color:#94a3b8;"></p>
      <p id="modalTrack" style="color:#38bdf8;"></p>
      <p id="modalAttendance" style="color:#10b981;font-weight:bold;"></p>
      <button onclick="closeModal()" style="background:#ef4444;width:100%;">Close Modal (Esc)</button>
    </div>
  </div>

  <script>
    const backdrop = document.getElementById("modalBackdrop");

    function showDetails(name, roll, track, att) {
      document.getElementById("modalName").textContent = name;
      document.getElementById("modalRoll").textContent = "Roll Number: " + roll;
      document.getElementById("modalTrack").textContent = "Specialization: " + track;
      document.getElementById("modalAttendance").textContent = att;
      backdrop.classList.add("active");
      document.body.style.overflow = "hidden";
    }

    function closeModal() {
      backdrop.classList.remove("active");
      document.body.style.overflow = "";
    }

    backdrop.addEventListener("click", (e) => {
      if (e.target === backdrop) closeModal();
    });

    window.addEventListener("keydown", (e) => {
      if (e.key === "Escape") closeModal();
    });
  </script>
</body>
</html>
Verified Assignment Code Solution (100% Tested & Ready to Run)

🎓4. Viva Check: Mandatory Conceptual Test

Why should document.body.style.overflow be set to "hidden" when an overlay modal opens?

5. Mandatory Step: Push to GitHub to Unlock Next Lesson

Target Repo: html-css-projects

Windows 11 Terminal / VS Code
1$
mkdir day-35
Create a new project folder (day-35)
2$
cd day-35
Change working directory to day-35
3$
git checkout -b feature/day-35-modal-dialogs
4$
git add index.html
5$
git commit -m "feat(day-35): implement dynamic modal dialogs overlay mechanics and keyboard accessibility"
Commit staged changes with a descriptive message
6$
git push origin feature/day-35-modal-dialogs
Push local commits directly to your remote GitHub repository
⌨️ Paste into terminal:Ctrl + V✨ Word wrap active (no horizontal cutoff)
Completion Prerequisites VerificationIncomplete Steps
Google Login
✔ Required
VS Code Implementation
Step 4 Viva Check
Own GitHub Project
Required

Exact GitHub Setup Guide & Expected Structure

Day 35 Requirements

Follow these exact folder and file names to prevent verification errors.

1. GitHub Repository
html-css-projects
Must be set to Public
2. Exact FolderNEW
day-35/ or bca-day-35/
Create inside repo root
3. Exact File NameREQUIRED
index.html
⚠️ No spaces or custom names
4. What to Submit Below
https://github.com/YOU/html-css-projects
Or direct link to index.html
Terminal Commands to Create & Push Day 35
1$
# 1. Enter your repository directory
2$
cd html-css-projects
Change working directory to html-css-projects
3$
# 2. Create the exact folder for Day 35
4$
mkdir day-35
Create a new project folder (day-35)
5$
cd day-35
Change working directory to day-35
6$
# 3. Create your code file: index.html
7$
# (Write your Day 35 homework code inside index.html)
8$
# 4. Save, stage, commit and push to GitHub:
9$
git add .
Stage all modified files and new assets for commit
10$
git commit -m "Day 35: Dynamic Modal Dialogs, Overlay Mechanics & Keyboard Accessibility"
Commit staged changes with a descriptive message
11$
git push origin main
Push local commits directly to your remote GitHub repository
⌨️ Paste into terminal:Ctrl + V✨ Word wrap active (no horizontal cutoff)
How to Avoid "Could not find your practical code file" Errors:
1.Use Lowercase index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.
2.Separate Day Folders: Create a new folder day-35/ for today so you don't overwrite previous days.
3.Ensure Public Visibility: If your GitHub repo is Private, automated validation cannot inspect your code. Set it to Public.
4.Check on GitHub Website: Before clicking "Verify", open your repo in Google Chrome to confirm your files were pushed to branch main.
📁 github.com/YOUR_USERNAME/html-css-projects
Branch: main
README.md# BCA Practical Portfolio overview
day-01/Day 1 Prior Lesson
└──index.html
day-02/Day 2 Prior Lesson
└──index.html
day-03/Day 3 Prior Lesson
└──index.html
day-04/Day 4 Prior Lesson
└──index.html
day-05/Day 5 Prior Lesson
└──index.html
day-06/Day 6 Prior Lesson
└──index.html
day-07/Day 7 Prior Lesson
└──index.html
day-08/Day 8 Prior Lesson
└──index.html
day-09/Day 9 Prior Lesson
└──index.html
day-10/Day 10 Prior Lesson
└──index.html
└──styles.css
day-11/Day 11 Prior Lesson
└──index.html
day-12/Day 12 Prior Lesson
└──index.html
day-13/Day 13 Prior Lesson
└──index.html
day-14/Day 14 Prior Lesson
└──index.html
day-15/Day 15 Prior Lesson
└──index.html
day-16/Day 16 Prior Lesson
└──index.html
day-17/Day 17 Prior Lesson
└──index.html
day-18/Day 18 Prior Lesson
└──index.html
day-19/Day 19 Prior Lesson
└──index.html
day-20/Day 20 Prior Lesson
└──index.html
└──styles.css
day-21/Day 21 Prior Lesson
└──index.html
day-22/Day 22 Prior Lesson
└──index.html
day-23/Day 23 Prior Lesson
└──index.html
day-24/Day 24 Prior Lesson
└──index.html
day-25/Day 25 Prior Lesson
└──index.html
day-26/Day 26 Prior Lesson
└──index.html
day-27/Day 27 Prior Lesson
└──index.html
day-28/Day 28 Prior Lesson
└──index.html
day-29/Day 29 Prior Lesson
└──index.html
day-30/Day 30 Prior Lesson
└──index.html
└──styles.css
day-31/Day 31 Prior Lesson
└──index.html
day-32/Day 32 Prior Lesson
└──index.html
day-33/Day 33 Prior Lesson
└──index.html
day-34/Day 34 Prior Lesson
└──index.html
day-35/✨ CREATE THIS FOLDER FOR TODAY (Day 35)
└──index.htmlMust contain:
Sequential Progression Enforced

You are welcome to read all notes, inspect code snippets, and practice all exercises of Day 35 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 34: DOM Event Delegation, Event Bubbling & Dynamic List Architecture first.

Complete Day 34 First
Day 34: DOM Event Delegation, Event Bubbling & Dynamic List Architecture
WhatsApp
Curriculum & Practical Systems Authored by Er. Manoj Kumar
NextSem Academy • BCA Practical Learning Portal