👋 Oi, mga repapips, Brian Dys here! I love music, photography, and creative stuff like UX design and art. This is a place where I collect my thoughts and works. Apart all these, I’m Jaycelle’s better half and Bryce’s dad. 🥰
Previously, I’ve discussed a class naming convention in the form of:
In this manner we are using a UI State class located up in the DOM tree – particularly in the
body to manipulate different UI elements under it.
Take this as an example: in a site’s header, both the main navigation and search form are located.
<header> <h2 class="accessible-name">Header Content</h2> <nav class="main-navigation">…</nav> <form class="search-form">…</form> </header>
What benefit do we get in having a global
class located higher in the DOM tree? It lets us control different parts of the UI depending on the site’s or app’s UI Type or UI State.
It is important to reserve the highest element you can put a class on – which is
html (for pertinent class names), thus, the second highest element we could attach a
class attribute to is
Going back to our example, we would use the following UI State class to define the state of the search form:
body class, in words, translates to “The UI State of the Search Form is Active”.
Now, whenever the search form is active, you can already manipulate the main navigation based on that state.
Take a look at the demo on CodePen:
See the Pen Using <body> to Define UI States and Types by Brian Dys Sahagun (@briandys) on CodePen.