|
4 | 4 | <meta charset="UTF-8"> |
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
6 | 6 | <title>Dropdown with Search & Checkboxes</title> |
7 | | - <style> |
8 | | - @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap'); |
9 | | - body { |
10 | | - font-family: "Poppins", sans-serif; |
11 | | - } |
12 | | - .selectDropdown { |
13 | | - position: relative; |
14 | | - display: block; |
15 | | - width: 100%; |
16 | | - } |
17 | | - .selectDropdownToggle { |
18 | | - width: 100%; |
19 | | - border: 1px solid #2F8B8A; |
20 | | - cursor: pointer; |
21 | | - background: #fff; |
22 | | - text-align: left; |
23 | | - border-radius: 8px; |
24 | | - color: #334155; |
25 | | - font-size: 12px; |
26 | | - font-weight: 500; |
27 | | - display: flex; |
28 | | - justify-content: space-between; |
29 | | - align-items: center; |
| 7 | + <link rel="stylesheet" href="./css/style.css"> |
30 | 8 |
|
31 | | - position: relative; |
32 | | - z-index: 9999; |
33 | | - } |
34 | | - .selectDropdownMenu { |
35 | | - display: none; |
36 | | - position: absolute; |
37 | | - width: 100%; |
38 | | - background: #fff; |
39 | | - border: 1px solid #ddd; |
40 | | - max-height: 300px; |
41 | | - overflow-x: hidden; |
42 | | - overflow-y: auto; |
43 | | - z-index: 1000; |
44 | | - box-shadow: 0px 4px 34px 0px #0000000D; |
45 | | - |
46 | | - margin-top: -10px; |
47 | | - border-bottom-right-radius: 12px; |
48 | | - border-bottom-left-radius: 12px; |
49 | | - } |
50 | | - .selectDropdownMenu input[type="text"] { |
51 | | - border: 1px solid #E2E8F0; |
52 | | - width: 97.3%; |
53 | | - color: #334155; |
54 | | - font-weight: 500; |
55 | | - padding: .5rem 1rem; |
56 | | - border-radius: 8px; |
57 | | - margin-bottom: .5rem; |
58 | | - } |
59 | | - .selectDropdownMenu input[type="text"]:focus{ |
60 | | - border: 1px solid #2F8B8A; |
61 | | - outline: none; |
62 | | - } |
63 | | - .selectDropdownItem { |
64 | | - display: flex; |
65 | | - justify-content: space-between; |
66 | | - align-items: center; |
67 | | - padding: 8px; |
68 | | - cursor: pointer; |
69 | | - width: 100%; |
70 | | - box-sizing: border-box; |
71 | | - font-size: 0.75rem; |
72 | | - color: #000000; |
73 | | - user-select: none; |
74 | | - } |
75 | | - .selectDropdownItem:focus, |
76 | | - .selectDropdownItem:hover { |
77 | | - background: rgba(47, 139, 138, 0.1); |
78 | | - color: #2F8B8A; |
79 | | - } |
80 | | - .selectDropdownItem span { |
81 | | - flex: 1; |
82 | | - } |
83 | | - .selectDropdownItem input[type="checkbox"] { |
84 | | - pointer-events: none; |
85 | | - } |
| 9 | + <meta charset="UTF-8"> |
| 10 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 11 | + |
| 12 | + <!-- ✅ Basic SEO Meta Tags --> |
| 13 | + <title>Dropdown with Search & Checkboxes | Custom Select Menu</title> |
| 14 | + <meta name="description" content="A custom dropdown select menu with a search bar and checkboxes. Perfect for multi-select functionality with a smooth user experience."> |
| 15 | + <meta name="keywords" content="dropdown, search dropdown, checkbox select, custom dropdown, HTML dropdown, JavaScript dropdown, multi-select"> |
| 16 | + <meta name="author" content="Ch Bappy"> |
| 17 | + |
| 18 | + <!-- ✅ Open Graph Meta Tags (For Social Media Sharing) --> |
| 19 | + <meta property="og:title" content="Dropdown with Search & Checkboxes | Custom Select Menu"> |
| 20 | + <meta property="og:description" content="A powerful, customizable dropdown with search functionality and checkboxes. Improve your form UX with this easy-to-use component."> |
| 21 | + <meta property="og:image" content="./img/OG.webp"> |
| 22 | + <meta property="og:url" content="https://chbappy-cse.github.io/dropdown-search-checkbox-javascript/"> |
| 23 | + <meta property="og:type" content="website"> |
| 24 | + |
| 25 | + <!-- ✅ Twitter Meta Tags (For Twitter Cards) --> |
| 26 | + <meta name="twitter:card" content="A feature-rich dropdown menu with search and multi-select checkboxes."> |
| 27 | + <meta name="twitter:title" content="Dropdown with Search & Checkboxes | Custom Select Menu"> |
| 28 | + <meta name="twitter:description" content="A feature-rich dropdown menu with search and multi-select checkboxes."> |
| 29 | + <meta name="twitter:image" content="./img/OG.webp"> |
| 30 | + |
| 31 | + <!-- ✅ Canonical URL (Avoids Duplicate Content Issues) --> |
| 32 | + <link rel="canonical" href="https://chbappy-cse.github.io/dropdown-search-checkbox-javascript/"> |
86 | 33 |
|
87 | | - .dropdown-toggle__title{ |
88 | | - width: 100%; |
89 | | - display: flex; |
90 | | - justify-content: space-between; |
91 | | - align-items: center; |
92 | | - padding: .75rem; |
93 | | - user-select: none; |
94 | | - } |
95 | | - </style> |
| 34 | + <!-- ✅ Favicon (For Browser Tabs & Mobile) --> |
| 35 | + <link rel="icon" type="image/png" href="./img/favicon.png"> |
| 36 | + |
| 37 | + <!-- ✅ Robots Meta Tag (Control Search Engine Indexing) --> |
| 38 | + <meta name="robots" content="index, follow"> <!-- Allows indexing --> |
96 | 39 | </head> |
97 | 40 | <body> |
98 | 41 |
|
99 | 42 | <div class="selectDropdown"> |
100 | 43 | <div class="selectDropdownToggle"> |
101 | 44 | <div class="dropdown-toggle__title"> |
102 | 45 | <span>Select Continent/ Region</span> |
103 | | - <img src="./chevron-up.svg"> |
| 46 | + <img id="dropdownIcon" src="./img/chevron-up.svg" alt="Dropdown with Search & Checkboxes"> |
104 | 47 | </div> |
105 | 48 | </div> |
106 | 49 | <div class="selectDropdownMenu"> |
107 | 50 | <div style="padding: 1rem;"> |
108 | 51 | <div class="slectInputSearch"> |
109 | 52 | <input type="text" id="searchBox" placeholder="Search..."> |
| 53 | + <img src="./img/search-input.svg" alt="Dropdown with Search & Checkboxes"> |
110 | 54 | </div> |
111 | 55 | <div id="selectDropdownItems"> |
112 | 56 | <div class="selectDropdownItem"><span>Apple</span> <input type="checkbox" value="Apple"></div> |
|
121 | 65 | </div> |
122 | 66 | </div> |
123 | 67 |
|
124 | | -<script> |
125 | | - const dropdown = document.querySelector(".selectDropdown"); |
126 | | - const dropdownToggle = document.querySelector(".selectDropdownToggle"); |
127 | | - const dropdownMenu = document.querySelector(".selectDropdownMenu"); |
128 | | - const searchBox = document.getElementById("searchBox"); |
129 | | - |
130 | | - // Toggle dropdown menu |
131 | | - dropdownToggle.addEventListener("click", () => { |
132 | | - dropdownMenu.style.display = dropdownMenu.style.display === "block" ? "none" : "block"; |
133 | | - }); |
134 | | - |
135 | | - // Toggle checkbox when clicking dropdown item |
136 | | - document.querySelectorAll(".selectDropdownItem").forEach(item => { |
137 | | - item.addEventListener("click", () => { |
138 | | - const checkbox = item.querySelector("input[type='checkbox']"); |
139 | | - checkbox.checked = !checkbox.checked; // Toggle checked state |
140 | | - }); |
141 | | - }); |
142 | | - |
143 | | - // Filter items based on search |
144 | | - searchBox.addEventListener("keyup", () => { |
145 | | - let searchValue = searchBox.value.toLowerCase(); |
146 | | - document.querySelectorAll(".selectDropdownItem").forEach(item => { |
147 | | - let text = item.textContent.toLowerCase(); |
148 | | - item.style.display = text.includes(searchValue) ? "flex" : "none"; |
149 | | - }); |
150 | | - }); |
151 | | - |
152 | | - // Close dropdown when clicking outside |
153 | | - document.addEventListener("click", (e) => { |
154 | | - if (!dropdown.contains(e.target)) { |
155 | | - dropdownMenu.style.display = "none"; |
156 | | - } |
157 | | - }); |
158 | | -</script> |
159 | | - |
| 68 | +<script src="./js/app.js"></script> |
160 | 69 | </body> |
161 | 70 | </html> |
0 commit comments