Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to name elements whose purpose is wrapping other elements? #87

Open
aradalvand opened this issue Nov 11, 2020 · 2 comments
Open

How to name elements whose purpose is wrapping other elements? #87

aradalvand opened this issue Nov 11, 2020 · 2 comments

Comments

@aradalvand
Copy link

aradalvand commented Nov 11, 2020

There is a common scenario that keeps coming up when I'm designing blocks with complex layouts, which is the need for what I would call "wrapper elements" (and I mean BEM elements). I'd appreciate any help:

Look at the above picture. This is a "course-card" block. Among its elements, there are these two:

.course-card__duration
.course-card__level

Pretty straight-forward so far. Now, in order to achieve the layout that you see there, I would need another element to wrap those two, and its CSS would look something like this:

.course-card__? {
   display: flex;
   justify-content: space-between;
}

Now, the question is, what should such an element be called according to BEM standards?! It's an element that doesn't serve any semantic purpose, it's just there for layout purposes. I could think of the following options:

- course-card__level-and-duration-wrapper (which obviously looks horrible!)
- course-card__basic-info (still not ideal)
- you tell me?

This is not a rare case. I encounter one of these "wrapper element" cases in almost every block I'm implementing. In this same block, you can see in the picture that there is a need for another wrapper element that wraps __instructor-avatar and __instructor-name.
I also couldn't find a satisfactory answer to this question, neither in en.bem.info nor in Stack Overflow or anywhere else, really.

  1. Should we add a "wrapper" or "container" suffix to the names of these kinds of elements?
  2. Should their names be as semantic as possible? For instance "basic-info" in the first example, and "instructor-info" in the second example? And we should avoid words like "wrapper" and "container" as much as possible?
  3. Are there any other guidelines and conventions in general to deal with these kinds of situations?

So, I'd appreciate any guidance. Thanks in advance.

@veged
Copy link

veged commented Nov 12, 2020

First of all, that’s very good question — thank you!

I’d like to say that there is no any strict guidelines on methodology level. But according to our experience I would recommend following priority order of decisions:

  1. try find proper semantic name (as you suggest basic-info) — really often it’s possible and, even if it will be slightly far-fetched, those “normal” uniq names will help you talk about different elements such this better than ugly uniform names
  2. try to think about those elements in terms of layout semantic — for example there is no problem to use names row/col if we do some tables, so if your block have clear sections in their skeleton there is no problem to have elements such subsection/mainsection
  3. even wrap name (or subname) can be used in simple cases where there are no a lot of such similar wraps (let’s say 1-2)

You already describe good understanding of problem so my answer only add 2nd option and suggest priority axis.

@aradalvand
Copy link
Author

aradalvand commented Nov 12, 2020

@veged Thanks a lot, Sergey, I appreciate your answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants