Skip to content

Commit 0b42628

Browse files
committed
Use uniquely and semantically named data attribute instead of data-id.
1 parent d574763 commit 0b42628

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/ui/views/ui_app.jade

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,14 @@ block content
110110
opacity: 0.8;
111111
}
112112

113-
.kibanaWelcomeView(
114-
data-id="kibanaWelcomeView"
115-
)
113+
.kibanaWelcomeView
116114
.kibanaLoader
117115
.kibanaLoader__logo
118116
.kibanaWelcomeLogo
119117
.kibanaLoader__content
120118
| Loading Kibana
121119
.kibanaLoadingMessage(
122-
data-id="kibanaLoadingMessage"
120+
data-remove-message-when-embedded
123121
)
124122
| Give me a moment here. I’m loading a whole bunch of code. Don’t worry, all this
125123
| good stuff will be cached up for next time!
@@ -129,9 +127,8 @@ block content
129127

130128
var hideLoadingMessage = /#.*[?&]embed(&|$|=true)/.test(window.location.href);
131129
if (hideLoadingMessage) {
132-
var loadingContainer = document.querySelector('[data-id="kibanaWelcomeView"]');
133-
var loadingMessage = document.querySelector('[data-id="kibanaLoadingMessage"]');
134-
loadingContainer.removeChild(loadingMessage);
130+
var loadingMessage = document.querySelector('[data-remove-message-when-embedded]');
131+
loadingMessage.parentNode.removeChild(loadingMessage);
135132
}
136133

137134
var buildNum = #{kibanaPayload.buildNum};

style_guides/css_style_guide.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# CSS Style Guide
33

44
- [CSS Style Guide](#css-style-guide)
5+
- [Selecting elements](#selecting-elements)
56
- [Using the preprocessor](#using-the-preprocessor)
67
- [Don't build concatenated selector names](#dont-build-concatenated-selector-names)
78
- [Avoid nested selectors](#avoid-nested-selectors)
@@ -15,6 +16,23 @@
1516
- [How to apply DRY](#how-to-apply-dry)
1617
- [Compelling reasons for using mixins](#compelling-reasons-for-using-mixins)
1718

19+
## Selecting elements
20+
21+
References to CSS selectors within JavaScript are difficult to discover, making it easy to accidentally
22+
break the UI when refactoring markup or CSS.
23+
24+
Instead, add a `data` attribute with a unique and descriptive name and select the element using that.
25+
26+
```html
27+
<div data-welcome-message>Hello, world</div>
28+
```
29+
30+
```javascript
31+
const welcomeMessage = document.querySelector('[data-welcome-message]');
32+
```
33+
34+
This uncouples our CSS from our JavaScript, making it easy to change each independently of the other.
35+
1836
## Using the preprocessor
1937

2038
### Don't build concatenated selector names

0 commit comments

Comments
 (0)