[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"quiz-css-focus-within-group-focus":44,"search-suggestions":60,"quiz-article-css-focus-within-group-focus":109,"path-membership-css-focus-within-group-focus":282},[4,20,32],{"id":5,"slug":6,"name":7,"tagline":8,"description":9,"accentFrom":10,"accentTo":11,"icon":12,"defaultLocale":13,"locales":14,"features":16,"position":19},"019fe637-3d33-714b-b57f-23e163ffca0c","dev","Web Development","Read it. Run it. Prove it.","A post a day on modern web development — most with an editable playground and a quiz that explains every answer. Free, no account needed.","violet-500","cyan-400","◇","en",[13,15],"fa",{"courses":17,"paths":17,"articles":17,"exams":18,"flashcards":18,"packages":17,"community":17,"certificates":17,"teams":17,"commerce":17},true,false,0,{"id":21,"slug":22,"name":23,"tagline":24,"description":25,"accentFrom":26,"accentTo":10,"icon":27,"defaultLocale":13,"locales":28,"features":30,"position":31},"019fe637-3dc2-754c-8657-0f175bfee7c6","lang","Languages","Learn a language the way you learn a codebase.","Grammar explained the way good documentation explains an API — one idea at a time, each with a quiz.","amber-400","⌘",[13,15,29],"es",{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":17,"packages":18,"community":17,"certificates":17,"teams":18,"commerce":18},2,{"id":33,"slug":34,"name":35,"tagline":36,"description":37,"accentFrom":38,"accentTo":39,"icon":40,"defaultLocale":13,"locales":41,"features":42,"position":43},"7b3c16f2-931d-410e-802e-e1fa4edab7de","soft","Soft Skills","The half of the job nobody wrote documentation for.","Weekly, on the parts of working life that decide more than your code does — first weeks, meetings, interviews, promotions, and the people around you. Written from what actually happens, and recorded as a podcast you can listen to on the walk.","emerald-400","teal-300","◉",[13],{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":18,"packages":18,"community":17,"certificates":18,"teams":18,"commerce":18},3,{"id":45,"slug":46,"kind":47,"title":48,"description":49,"config":50,"verticalId":5,"vertical":55,"course":52,"_count":56,"access":57,"attempts":59,"questionCount":51},"01a22fd5-4bb6-752f-90f2-c91aeb200710","css-focus-within-group-focus","PRACTICE_QUIZ",":focus-within — test yourself","Seven questions on what :focus-within actually matches, how it differs from :focus and :focus-visible, and why relatedTarget checks exist in the first place.",{"questionCount":51,"timeLimitSec":52,"shuffleQuestions":18,"shuffleOptions":17,"negativeMarking":19,"passScorePct":53,"maxAttempts":52,"revealAnswers":54,"allowFlagging":18,"allowBacktracking":17},7,null,70,"AFTER_SUBMIT",{"slug":6,"name":7},{"questions":51},{"allowed":17,"reason":58},"FREE",[],[61,65,69,73,77,81,85,89,93,97,101,105],{"slug":62,"name":63,"articles":64},"webdev","Webdev",203,{"slug":66,"name":67,"articles":68},"javascript","Javascript",159,{"slug":70,"name":71,"articles":72},"frontend","Frontend",106,{"slug":74,"name":75,"articles":76},"tutorial","Tutorial",93,{"slug":78,"name":79,"articles":80},"css","Css",60,{"slug":82,"name":83,"articles":84},"typescript","Typescript",38,{"slug":86,"name":87,"articles":88},"performance","Performance",34,{"slug":90,"name":91,"articles":92},"programming","Programming",27,{"slug":94,"name":95,"articles":96},"react","React",23,{"slug":98,"name":99,"articles":100},"node","Node",19,{"slug":102,"name":103,"articles":104},"browser","Browser",18,{"slug":106,"name":107,"articles":108},"nextjs","Nextjs",14,{"id":110,"slug":46,"title":111,"subtitle":52,"excerpt":112,"coverUrl":113,"locale":13,"readingMinutes":114,"publishedAt":115,"viewCount":116,"likeCount":19,"commentCount":19,"author":117,"vertical":122,"topic":123,"tags":125,"_count":130,"playground":132,"body":134,"bodyMd":268,"seo":269,"translationGroupId":272,"series":52,"podcastUrl":52,"verticalId":5,"thread":273,"assessments":275,"translations":278,"quiz":280},"01a22fd5-4b5e-7649-83f0-a37d6da8cd14","I Stopped Checking relatedTarget. :focus-within Does It in CSS.","A search box's own clear button kept un-focusing the whole wrapper, so I started checking event.relatedTarget on every blur to tell 'focus left the widget' from 'focus moved inside it.' :focus-within in CSS made the check unnecessary.","\u002Fmedia\u002Fcovers\u002Fcss-focus-within-group-focus.png",5,"2026-12-04T21:44:50.650Z",74,{"id":118,"name":119,"username":120,"avatarUrl":52,"headline":121},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":78,"name":124},"CSS",[126,127,128,129],{"slug":78,"name":79,"color":52},{"slug":70,"name":71,"color":52},{"slug":62,"name":63,"color":52},{"slug":74,"name":75,"color":52},{"assessments":131},1,{"slug":46,"title":133},":focus-within — interactive playground",{"blocks":135,"version":131},[136,140,143,147,150,156,159,162,166,169,173,176,179,183,186,189,192,199,202,205,208,214,217,220,223,226,229,232,235,238,241,244,247,250,253,256,259,262],{"id":137,"html":138,"type":139},"b1","\u003Cp>I built a search box with a clear button inside it — the little × that shows up once you&#39;ve typed something. Standard stuff. The input had a nice blue ring when focused, so I matched it on the wrapper too: \u003Ccode>border-color: var(--focus-color)\u003C\u002Fcode> the moment the input gets focus, so the whole pill looks selected, not just the text caret.\u003C\u002Fp>","paragraph",{"id":141,"html":142,"type":139},"b2","\u003Cp>It worked, until a teammate typed a query and clicked the ×. For one frame, the wrapper&#39;s border flashed back to gray — like the whole box had lost focus — before the input (correctly) still showing the cleared, empty state kept its own focus ring. It looked like a rendering glitch. It wasn&#39;t. It was \u003Ccode>onBlur\u003C\u002Fcode> doing exactly what \u003Ccode>onBlur\u003C\u002Fcode> does.\u003C\u002Fp>",{"id":144,"html":145,"text":145,"type":146,"level":31},"b3","The fix everyone reaches for first","heading",{"id":148,"html":149,"type":139},"b4","\u003Cp>The wrapper&#39;s &quot;focused&quot; look was driven by state, toggled from the input&#39;s own focus and blur events:\u003C\u002Fp>",{"id":151,"code":152,"type":153,"language":154,"highlight":155},"b5","function SearchBox() {\n  const [focused, setFocused] = useState(false);\n\n  return (\n    \u003Cdiv className={focused ? \"search focused\" : \"search\"}>\n      \u003Cinput\n        onFocus={() => setFocused(true)}\n        onBlur={() => setFocused(false)}\n      \u002F>\n      \u003Cbutton onClick={clear}>×\u003C\u002Fbutton>\n    \u003C\u002Fdiv>\n  );\n}","code","jsx",[],{"id":157,"html":158,"type":139},"b6","\u003Cp>Click the ×, and here&#39;s the order of events: the button steals focus away from the input, so the input&#39;s \u003Ccode>blur\u003C\u002Fcode> fires, \u003Ccode>setFocused(false)\u003C\u002Fcode> runs, and the wrapper&#39;s &quot;focused&quot; class disappears — a full render cycle before anyone notices the focus is still \u003Cem>inside the same component\u003C\u002Fem>, just on a different element.\u003C\u002Fp>",{"id":160,"html":161,"type":139},"b7","\u003Cp>The standard patch, and the one you&#39;ll find in a dozen Stack Overflow answers for exactly this: check where focus is going before you believe it left.\u003C\u002Fp>",{"id":163,"code":164,"type":153,"language":154,"highlight":165},"b8","onBlur={(e) => {\n  if (!e.currentTarget.contains(e.relatedTarget)) {\n    setFocused(false);\n  }\n}}",[],{"id":167,"html":168,"type":139},"b9","\u003Cp>\u003Ccode>relatedTarget\u003C\u002Fcode> is the element about to receive focus — MDN documents it on the \u003Ccode>FocusEvent\u003C\u002Fcode> interface for exactly this reason. \u003Ccode>currentTarget.contains(relatedTarget)\u003C\u002Fcode> asks &quot;is the new focus target a descendant of the wrapper I&#39;m attached to?&quot; If yes, don&#39;t un-focus. It works. It also has to be written again for every dropdown, every combobox, every form row with more than one focusable child — and it quietly breaks the moment the new target sits behind a portal or an iframe, where \u003Ccode>contains()\u003C\u002Fcode> can&#39;t see it at all.\u003C\u002Fp>",{"id":170,"html":171,"text":172,"type":146,"level":31},"b10","The actual problem: blur is per-element, CSS doesn&#39;t know your widget is one thing","The actual problem: blur is per-element, CSS doesn't know your widget is one thing",{"id":174,"html":175,"type":139},"b11","\u003Cp>\u003Ccode>focus\u003C\u002Fcode> and \u003Ccode>blur\u003C\u002Fcode> are defined per element. The browser has no built-in notion that the input and its clear button are &quot;one search box&quot; — that grouping exists only in your head and your JSX. So every time focus moves \u003Cem>within\u003C\u002Fem> a thing you consider one unit, the browser reports it as a departure from one element and an arrival at another, and you&#39;re stuck inferring &quot;same widget&quot; from DOM containment by hand.\u003C\u002Fp>",{"id":177,"html":178,"type":139},"b12","\u003Cp>CSS already has the word for that grouping. It&#39;s a pseudo-class, not a state you manage:\u003C\u002Fp>",{"id":180,"code":181,"type":153,"language":78,"highlight":182},"b13",".search:focus-within {\n  border-color: var(--focus-color);\n}",[],{"id":184,"html":185,"type":139},"b14","\u003Cp>\u003Ccode>:focus-within\u003C\u002Fcode> matches an element if \u003Cem>that element or any descendant\u003C\u002Fem> currently has focus. Click into the input — matches. Tab to the clear button — still matches, because the button is a descendant of \u003Ccode>.search\u003C\u002Fcode>. Click the × to actually blur out of the whole component — only then does it stop matching. No \u003Ccode>useState\u003C\u002Fcode>, no \u003Ccode>onFocus\u003C\u002Fcode>\u002F\u003Ccode>onBlur\u003C\u002Fcode> pair, no \u003Ccode>relatedTarget\u003C\u002Fcode> containment check, and no render at all: the browser repaints the border because the CSS rule re-evaluates, not because your component re-rendered.\u003C\u002Fp>",{"id":187,"html":188,"text":188,"type":146,"level":31},"b15","Quick gut check before you keep scrolling",{"id":190,"html":191,"type":139},"b16","\u003Cp>\u003Ccode>:focus\u003C\u002Fcode>, \u003Ccode>:focus-visible\u003C\u002Fcode>, and \u003Ccode>:focus-within\u003C\u002Fcode> read like three names for the same idea. They&#39;re not:\u003C\u002Fp>",{"id":193,"type":194,"items":195,"ordered":18},"b17","list",[196,197,198],"\u003Cstrong>\u003Ccode>:focus\u003C\u002Fcode>\u003C\u002Fstrong> — matches the element that literally has focus right now. Just that one element.","\u003Cstrong>\u003Ccode>:focus-visible\u003C\u002Fcode>\u003C\u002Fstrong> — matches only when the browser thinks the focus indicator should show (keyboard navigation, mostly — a mouse click on a \u003Ccode>&lt;button&gt;\u003C\u002Fcode> usually doesn&#39;t trigger it). I wrote about this one back when \u003Ccode>outline: none\u003C\u002Fcode> was the fight.","\u003Cstrong>\u003Ccode>:focus-within\u003C\u002Fcode>\u003C\u002Fstrong> — matches an \u003Cem>ancestor\u003C\u002Fem> of whatever has focus, all the way up. The one this post is about.",{"id":200,"html":201,"type":139},"b18","\u003Cp>They compose. \u003Ccode>.search:focus-within:not(:focus)\u003C\u002Fcode> matches the wrapper exactly when focus is inside it but not \u003Cem>on\u003C\u002Fem> it — useful if the wrapper itself is also focusable and you want different styling for &quot;I&#39;m focused&quot; versus &quot;something inside me is.&quot;\u003C\u002Fp>",{"id":203,"html":204,"text":204,"type":146,"level":31},"b19","Where this earns its keep beyond one search box",{"id":206,"html":207,"type":139},"b20","\u003Cp>The same pattern shows up anywhere a widget is more than one focusable element and you want it to read as one thing:\u003C\u002Fp>",{"id":209,"type":194,"items":210,"ordered":18},"b21",[211,212,213],"\u003Cstrong>Form rows\u003C\u002Fstrong> — highlight the whole label-plus-input row when the input inside it is focused, without a listener on every row.","\u003Cstrong>Toolbars with grouped fields\u003C\u002Fstrong> — a date range picker with two inputs should look &quot;active&quot; if focus is on either one.","\u003Cstrong>Custom dropdowns and comboboxes\u003C\u002Fstrong> — keep a wrapper visually &quot;open&quot; while focus bounces between the trigger and the menu, instead of tracking that by hand.",{"id":215,"html":216,"type":139},"b22","\u003Cp>One honest limit: \u003Ccode>:focus-within\u003C\u002Fcode> is CSS-only. It changes what gets \u003Cem>styled\u003C\u002Fem>, not what your JavaScript \u003Cem>knows\u003C\u002Fem>. If a component genuinely needs a boolean in JS — to fire an analytics event, say, or gate some other logic — you still need \u003Ccode>focus\u003C\u002Fcode>\u002F\u003Ccode>blur\u003C\u002Fcode> listeners (with the \u003Ccode>relatedTarget\u003C\u002Fcode> check, if you only want to know when focus leaves the whole group). What you get to delete is every line of state and every re-render that existed \u003Cem>only\u003C\u002Fem> to drive a style.\u003C\u002Fp>",{"id":218,"html":219,"type":139},"b23","\u003Cp>Support isn&#39;t the concern here — \u003Ccode>:focus-within\u003C\u002Fcode> has shipped in every engine for years (Chrome 60+, Firefox 52+, Safari 10.1+), no polyfill, no flag. The concern was ever having written the JS in the first place.\u003C\u002Fp>",{"id":221,"html":222,"type":139},"b24","\u003C!-- playground:start -->",{"id":224,"html":225,"text":225,"type":146,"level":31},"b25","🎮 Try it yourself",{"id":227,"html":228,"type":139},"b26","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":230,"html":231,"type":139},"b27","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":233,"html":234,"type":139},"b28","\u003C!-- playground:end -->",{"id":236,"html":237,"type":139},"b29","\u003C!-- quiz:start -->",{"id":239,"html":240,"text":240,"type":146,"level":31},"b30","🧠 Test yourself",{"id":242,"html":243,"type":139},"b31","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus\u002Fquiz\">Take the 7-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":245,"html":246,"type":139},"b32","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":248,"html":249,"type":139},"b33","\u003C!-- quiz:end -->",{"id":251,"html":252,"type":139},"b34","\u003Cp>Go find the component in your codebase with an \u003Ccode>onFocus\u003C\u002Fcode>\u002F\u003Ccode>onBlur\u003C\u002Fcode> pair whose only job is toggling a CSS class on a parent. I&#39;d bet money you have at least one. Rip it out and see if the browser was already willing to do it for free — then tell me what broke, because I&#39;d genuinely like to hear about the one case where it didn&#39;t just work.\u003C\u002Fp>",{"id":254,"type":255},"b35","divider",{"id":257,"html":258,"type":139},"b36","\u003Cp>🚀 \u003Cstrong>Want more like this?\u003C\u002Fstrong> Every guide, playground, and quiz lives on \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">bestpractic.org\u003C\u002Fa>\u003C\u002Fstrong> — open it and \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">sign up free\u003C\u002Fa>\u003C\u002Fstrong> so the next one finds you.\u003C\u002Fp>",{"id":260,"html":261,"type":139},"b37","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":263,"type":194,"items":264,"ordered":18},"b38",[265,266,267],"⭐ \u003Cstrong>GitHub\u003C\u002Fstrong> — follow me and star the projects: \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fparsajiravand\">github.com\u002Fparsajiravand\u003C\u002Fa>","💬 \u003Cstrong>Discord\u003C\u002Fstrong> — join the frontend best-practices community: \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ\">discord.gg\u002Fd9KRhuAwQ\u003C\u002Fa>","📸 \u003Cstrong>Instagram\u003C\u002Fstrong> — frontend best practices, daily: \u003Ca href=\"https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F\">@bestpractice___\u003C\u002Fa>","I built a search box with a clear button inside it — the little × that shows up once you've typed something. Standard stuff. The input had a nice blue ring when focused, so I matched it on the wrapper too: `border-color: var(--focus-color)` the moment the input gets focus, so the whole pill looks selected, not just the text caret.\n\nIt worked, until a teammate typed a query and clicked the ×. For one frame, the wrapper's border flashed back to gray — like the whole box had lost focus — before the input (correctly) still showing the cleared, empty state kept its own focus ring. It looked like a rendering glitch. It wasn't. It was `onBlur` doing exactly what `onBlur` does.\n\n## The fix everyone reaches for first\n\nThe wrapper's \"focused\" look was driven by state, toggled from the input's own focus and blur events:\n\n```jsx\nfunction SearchBox() {\n  const [focused, setFocused] = useState(false);\n\n  return (\n    \u003Cdiv className={focused ? \"search focused\" : \"search\"}>\n      \u003Cinput\n        onFocus={() => setFocused(true)}\n        onBlur={() => setFocused(false)}\n      \u002F>\n      \u003Cbutton onClick={clear}>×\u003C\u002Fbutton>\n    \u003C\u002Fdiv>\n  );\n}\n```\n\nClick the ×, and here's the order of events: the button steals focus away from the input, so the input's `blur` fires, `setFocused(false)` runs, and the wrapper's \"focused\" class disappears — a full render cycle before anyone notices the focus is still *inside the same component*, just on a different element.\n\nThe standard patch, and the one you'll find in a dozen Stack Overflow answers for exactly this: check where focus is going before you believe it left.\n\n```jsx\nonBlur={(e) => {\n  if (!e.currentTarget.contains(e.relatedTarget)) {\n    setFocused(false);\n  }\n}}\n```\n\n`relatedTarget` is the element about to receive focus — MDN documents it on the `FocusEvent` interface for exactly this reason. `currentTarget.contains(relatedTarget)` asks \"is the new focus target a descendant of the wrapper I'm attached to?\" If yes, don't un-focus. It works. It also has to be written again for every dropdown, every combobox, every form row with more than one focusable child — and it quietly breaks the moment the new target sits behind a portal or an iframe, where `contains()` can't see it at all.\n\n## The actual problem: blur is per-element, CSS doesn't know your widget is one thing\n\n`focus` and `blur` are defined per element. The browser has no built-in notion that the input and its clear button are \"one search box\" — that grouping exists only in your head and your JSX. So every time focus moves *within* a thing you consider one unit, the browser reports it as a departure from one element and an arrival at another, and you're stuck inferring \"same widget\" from DOM containment by hand.\n\nCSS already has the word for that grouping. It's a pseudo-class, not a state you manage:\n\n```css\n.search:focus-within {\n  border-color: var(--focus-color);\n}\n```\n\n`:focus-within` matches an element if *that element or any descendant* currently has focus. Click into the input — matches. Tab to the clear button — still matches, because the button is a descendant of `.search`. Click the × to actually blur out of the whole component — only then does it stop matching. No `useState`, no `onFocus`\u002F`onBlur` pair, no `relatedTarget` containment check, and no render at all: the browser repaints the border because the CSS rule re-evaluates, not because your component re-rendered.\n\n## Quick gut check before you keep scrolling\n\n`:focus`, `:focus-visible`, and `:focus-within` read like three names for the same idea. They're not:\n\n- **`:focus`** — matches the element that literally has focus right now. Just that one element.\n- **`:focus-visible`** — matches only when the browser thinks the focus indicator should show (keyboard navigation, mostly — a mouse click on a `\u003Cbutton>` usually doesn't trigger it). I wrote about this one back when `outline: none` was the fight.\n- **`:focus-within`** — matches an *ancestor* of whatever has focus, all the way up. The one this post is about.\n\nThey compose. `.search:focus-within:not(:focus)` matches the wrapper exactly when focus is inside it but not *on* it — useful if the wrapper itself is also focusable and you want different styling for \"I'm focused\" versus \"something inside me is.\"\n\n## Where this earns its keep beyond one search box\n\nThe same pattern shows up anywhere a widget is more than one focusable element and you want it to read as one thing:\n\n- **Form rows** — highlight the whole label-plus-input row when the input inside it is focused, without a listener on every row.\n- **Toolbars with grouped fields** — a date range picker with two inputs should look \"active\" if focus is on either one.\n- **Custom dropdowns and comboboxes** — keep a wrapper visually \"open\" while focus bounces between the trigger and the menu, instead of tracking that by hand.\n\nOne honest limit: `:focus-within` is CSS-only. It changes what gets *styled*, not what your JavaScript *knows*. If a component genuinely needs a boolean in JS — to fire an analytics event, say, or gate some other logic — you still need `focus`\u002F`blur` listeners (with the `relatedTarget` check, if you only want to know when focus leaves the whole group). What you get to delete is every line of state and every re-render that existed *only* to drive a style.\n\nSupport isn't the concern here — `:focus-within` has shipped in every engine for years (Chrome 60+, Firefox 52+, Safari 10.1+), no polyfill, no flag. The concern was ever having written the JS in the first place.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 7-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus\u002Fquiz)**\n\n_Instant feedback, a hint on every question, and an explanation for each answer — right or wrong._\n\n\u003C!-- quiz:end -->\n\nGo find the component in your codebase with an `onFocus`\u002F`onBlur` pair whose only job is toggling a CSS class on a parent. I'd bet money you have at least one. Rip it out and see if the browser was already willing to do it for free — then tell me what broke, because I'd genuinely like to hear about the one case where it didn't just work.\n\n---\n\n🚀 **Want more like this?** Every guide, playground, and quiz lives on **[bestpractic.org](https:\u002F\u002Fbestpractic.org\u002F)** — open it and **[sign up free](https:\u002F\u002Fbestpractic.org\u002F)** so the next one finds you.\n\n*Thanks for reading! Let's stay connected:*\n\n- ⭐ **GitHub** — follow me and star the projects: [github.com\u002Fparsajiravand](https:\u002F\u002Fgithub.com\u002Fparsajiravand)\n- 💬 **Discord** — join the frontend best-practices community: [discord.gg\u002Fd9KRhuAwQ](https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ)\n- 📸 **Instagram** — frontend best practices, daily: [@bestpractice___](https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F)",{"title":111,"canonical":270,"description":271},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-focus-within-group-focus","A search box's own clear button kept un-focusing the whole wrapper, so I started checking event.relatedTarget on every blur to tell 'focus left the widget' from 'focus moved inside","01a22fd5-4b5e-7649-83f0-a5cf309d07d4",{"id":274,"locked":18},"01a22fd5-4b8c-7745-b402-87bcd47b1cc4",[276],{"id":45,"slug":46,"title":48,"_count":277},{"questions":51},[279],{"locale":13,"slug":46},{"id":45,"slug":46,"title":48,"_count":281,"questionCount":51},{"questions":51},[]]