Skip to content

Commit 7c76bc4

Browse files
authored
Merge pull request #922 from primer/more-select-menu-improvements
More SelectMenu improvements
2 parents 033ee0a + bc7cbe7 commit 7c76bc4

File tree

3 files changed

+50
-80
lines changed

3 files changed

+50
-80
lines changed

deprecations.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
*/
66
const versionDeprecations = {
77
'14.0.0': [
8+
{
9+
selectors: [
10+
'.SelectMenu-item+.SelectMenu-item',
11+
'.SelectMenu-divider:first-child',
12+
'.SelectMenu-divider:last-child',
13+
'.SelectMenu--hasFilter .SelectMenu-item:last-child',
14+
'.SelectMenu-item[aria-checked="true"] .SelectMenu-icon'
15+
],
16+
message: `These selectors are deprecated and not used anymore.`
17+
},
818
{
919
selectors: [
1020
'.flex-item-equal',

docs/content/components/select-menu.md

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ In case the Select Menu should be aligned to the right, use `SelectMenu right-0`
8585

8686
## Selected state
8787

88-
Add a `.SelectMenu-icon .octicon-check` icon and it will show up when `aria-checked="true"` is set.
88+
If the `SelectMenu` should show a check icon for selected items, use the `SelectMenu-icon SelectMenu-icon--check` classes. It will make the check icon show when `aria-checked="true"` is set.
8989

9090
```html live
9191
<details class="details-reset details-overlay" open>
@@ -108,68 +108,28 @@ Add a `.SelectMenu-icon .octicon-check` icon and it will show up when `aria-chec
108108
</header>
109109
<div class="SelectMenu-list">
110110
<button class="SelectMenu-item" role="menuitemcheckbox" aria-checked="true">
111-
<!-- <%= octicon "check", class: "SelectMenu-icon" %> -->
112-
<svg
113-
width="12"
114-
height="16"
115-
viewBox="0 0 12 16"
116-
class="octicon octicon-check SelectMenu-icon"
117-
aria-hidden="true"
118-
>
119-
<path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" />
120-
</svg>
111+
<!-- <%= octicon "check", class: "SelectMenu-icon SelectMenu-icon--check" %> -->
112+
<svg class="SelectMenu-icon SelectMenu-icon--check octicon octicon-check" width="12" height="16" viewBox="0 0 12 16" aria-hidden="true" ><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" /></svg>
121113
Selected state
122114
</button>
123115
<button class="SelectMenu-item" role="menuitemcheckbox">
124-
<!-- <%= octicon "check", class: "SelectMenu-icon" %> -->
125-
<svg
126-
width="12"
127-
height="16"
128-
viewBox="0 0 12 16"
129-
class="octicon octicon-check SelectMenu-icon"
130-
aria-hidden="true"
131-
>
132-
<path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" />
133-
</svg>
116+
<!-- <%= octicon "check", class: "SelectMenu-icon SelectMenu-icon--check" %> -->
117+
<svg class="SelectMenu-icon SelectMenu-icon--check octicon octicon-check" width="12" height="16" viewBox="0 0 12 16" aria-hidden="true" ><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" /></svg>
134118
Default state
135119
</button>
136120
<button class="SelectMenu-item" role="menuitemcheckbox" aria-checked="true">
137-
<!-- <%= octicon "check", class: "SelectMenu-icon" %> -->
138-
<svg
139-
width="12"
140-
height="16"
141-
viewBox="0 0 12 16"
142-
class="octicon octicon-check SelectMenu-icon"
143-
aria-hidden="true"
144-
>
145-
<path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" />
146-
</svg>
121+
<!-- <%= octicon "check", class: "SelectMenu-icon SelectMenu-icon--check" %> -->
122+
<svg class="SelectMenu-icon SelectMenu-icon--check octicon octicon-check" width="12" height="16" viewBox="0 0 12 16" aria-hidden="true" ><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" /></svg>
147123
Selected state
148124
</button>
149125
<button class="SelectMenu-item" role="menuitemcheckbox">
150-
<!-- <%= octicon "check", class: "SelectMenu-icon" %> -->
151-
<svg
152-
width="12"
153-
height="16"
154-
viewBox="0 0 12 16"
155-
class="octicon octicon-check SelectMenu-icon"
156-
aria-hidden="true"
157-
>
158-
<path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" />
159-
</svg>
126+
<!-- <%= octicon "check", class: "SelectMenu-icon SelectMenu-icon--check" %> -->
127+
<svg class="SelectMenu-icon SelectMenu-icon--check octicon octicon-check" width="12" height="16" viewBox="0 0 12 16" aria-hidden="true" ><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" /></svg>
160128
Default state
161129
</button>
162130
<button class="SelectMenu-item" role="menuitemcheckbox">
163-
<!-- <%= octicon "check", class: "SelectMenu-icon" %> -->
164-
<svg
165-
width="12"
166-
height="16"
167-
viewBox="0 0 12 16"
168-
class="octicon octicon-check SelectMenu-icon"
169-
aria-hidden="true"
170-
>
171-
<path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" />
172-
</svg>
131+
<!-- <%= octicon "check", class: "SelectMenu-icon SelectMenu-icon--check" %> -->
132+
<svg class="SelectMenu-icon SelectMenu-icon--check octicon octicon-check" width="12" height="16" viewBox="0 0 12 16" aria-hidden="true" ><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z" /></svg>
173133
Default state
174134
</button>
175135
</div>
@@ -183,7 +143,7 @@ Add a `.SelectMenu-icon .octicon-check` icon and it will show up when `aria-chec
183143

184144
## List items
185145

186-
The list of items is arguably the most important subcomponent within the menu. Build them out of anchors, buttons, or just about any [interactive content](http://w3c.github.io/html/dom.html#interactive-content). List items are also customizable with options for avatars, additional icons, and multiple lines of text. Use utility classes like `mr-2`, `d-flex` or `float-right` in case more custom styling is needed.
146+
The list of items is arguably the most important subcomponent within the menu. Build them out of anchors, buttons, or just about any [interactive content](http://w3c.github.io/html/dom.html#interactive-content). List items are also customizable with options for avatars, additional icons, and multiple lines of text. Use utility classes in case more custom styling is needed.
187147

188148
```html live
189149
<details class="details-reset details-overlay" open>
@@ -208,6 +168,11 @@ The list of items is arguably the most important subcomponent within the menu. B
208168
<button class="SelectMenu-item" role="menuitem">
209169
Text only
210170
</button>
171+
<button class="SelectMenu-item" role="menuitem">
172+
<!-- <%= octicon "pin", class: "SelectMenu-icon" %> -->
173+
<svg class="SelectMenu-icon octicon octicon-pin" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M10 1.2V2l.5 1L6 6H2.2c-.44 0-.67.53-.34.86L5 10l-4 5 5-4 3.14 3.14a.5.5 0 00.86-.34V10l3-4.5 1 .5h.8c.44 0 .67-.53.34-.86L10.86.86a.5.5 0 00-.86.34z"></path></svg>
174+
With an icon
175+
</button>
211176
<button class="SelectMenu-item" role="menuitem">
212177
<img
213178
class="avatar avatar-small mr-2"
@@ -247,7 +212,7 @@ The list of items is arguably the most important subcomponent within the menu. B
247212
</details>
248213

249214
<div class="d-sm-none" style="height: 600px"><!-- min height for < sm --></div>
250-
<div class="d-none d-sm-block" style="height: 300px"><!-- min height for > sm --></div>
215+
<div class="d-none d-sm-block" style="height: 320px"><!-- min height for > sm --></div>
251216
```
252217

253218
## Divider
@@ -350,7 +315,7 @@ Also consider adding a `.SelectMenu-footer` at the bottom. It can be used for ad
350315
</details>
351316

352317
<div class="d-sm-none" style="height: 600px"> <!-- min height for < sm --> </div>
353-
<div class="d-none d-sm-block" style="height: 380px"> <!-- min height for > sm --> </div>
318+
<div class="d-none d-sm-block" style="height: 500px"> <!-- min height for > sm --> </div>
354319
```
355320

356321
## Tabs
@@ -430,7 +395,7 @@ A `SelectMenu-message` can be used to show different kind of messages to a user.
430395
<div class="SelectMenu-list">
431396
<button class="SelectMenu-item" role="menuitem">Item 1</button>
432397
<button class="SelectMenu-item" role="menuitem">Item 2</button>
433-
<div class="SelectMenu-message border-bottom border-top bg-red-0 text-red p-2">Message goes here</div>
398+
<div class="SelectMenu-message bg-red-0 text-red p-2">Message goes here</div>
434399
<button class="SelectMenu-item" role="menuitem">Item 3</button>
435400
</div>
436401
</div>

src/select-menu/select-menu.scss

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// selector-max-type is needed for body:not(.intent-mouse) to target keyboard only styles.
44
// TODO: Introduce an additional .intent-keyboard class
55

6+
$SelectMenu-max-height: 480px !default;
7+
68
// Select Menu
79
//
810
// A more advanced menu with support for navigation, filtering, and more.
@@ -85,7 +87,7 @@
8587
@include breakpoint(sm) {
8688
width: 300px;
8789
height: auto;
88-
max-height: 350px;
90+
max-height: $SelectMenu-max-height;
8991
margin: $spacer-1 0 $spacer-3 0;
9092
font-size: $font-size-small;
9193
border: $border-width $border-style $border-gray-dark;
@@ -163,6 +165,8 @@
163165
position: relative;
164166
padding: 0;
165167
margin: 0;
168+
// stylelint-disable-next-line primer/spacing
169+
margin-bottom: -$border-width; // Hides the last border in the list
166170
flex: auto;
167171
overflow-x: hidden;
168172
overflow-y: auto;
@@ -186,11 +190,7 @@
186190
cursor: pointer;
187191
background-color: $bg-white;
188192
border: 0;
189-
190-
& + & {
191-
// Add a top border only if the above element also is a list item
192-
border-top: $border-width $border-style $border-gray-light;
193-
}
193+
border-bottom: $border-width $border-style $border-gray-light;
194194

195195
@include breakpoint(sm) {
196196
padding-top: $spacer-2;
@@ -200,11 +200,16 @@
200200

201201
// Icon
202202
//
203-
// The icon shown on the left of a list item. Typically a check icon.
203+
// Icon shown on the left of a list item.
204204

205205
.SelectMenu-icon {
206206
width: $spacer-3; // fixed width to make sure following content aligns
207207
margin-right: $spacer-2;
208+
flex-shrink: 0;
209+
}
210+
211+
// Check icon
212+
.SelectMenu-icon--check {
208213
visibility: hidden;
209214
transition: transform 0.12s cubic-bezier(0.5, 0.1, 1, 0.5), visibility 0s 0.12s linear;
210215
transform: scale(0);
@@ -274,6 +279,10 @@
274279
//
275280
// A container used to show different kinds of content. Like a message, a blankslate or the loading animation.
276281

282+
.SelectMenu-message {
283+
border-bottom: $border-width $border-style $border-gray-light;
284+
}
285+
277286
.SelectMenu-message,
278287
.SelectMenu-blankslate,
279288
.SelectMenu-loading {
@@ -293,23 +302,15 @@
293302
font-weight: $font-weight-bold;
294303
color: $text-gray-light;
295304
background-color: $bg-gray;
296-
border-top: $border;
297-
border-bottom: $border;
298-
299-
&:first-child {
300-
border-top: 0;
301-
}
302-
303-
&:last-child {
304-
border-bottom: 0;
305-
}
305+
border-bottom: $border-width $border-style $border-gray-light;
306306
}
307307

308308
// Footer
309309
//
310310
// A container at the bottom.
311311

312312
.SelectMenu-footer {
313+
z-index: 0; // Avoid top border from getting covered by the negative margin of the list
313314
padding: $spacer-2 $spacer-3;
314315
font-size: $font-size-small;
315316
color: $text-gray-light;
@@ -333,16 +334,10 @@
333334

334335
@include breakpoint(sm) {
335336
height: auto;
336-
max-height: 350px;
337+
max-height: $SelectMenu-max-height;
337338
margin-top: $spacer-1;
338339
}
339340
}
340-
341-
// Show bottom "border" for the last item when the list doesn't take up the whole height
342-
.SelectMenu-item:last-child {
343-
// stylelint-disable-next-line primer/box-shadow
344-
box-shadow: 0 $border-width 0 lighten($gray-200, 3%);
345-
}
346341
}
347342

348343
// States
@@ -368,7 +363,7 @@
368363
font-weight: $font-weight-semibold;
369364
color: $text-gray-dark;
370365

371-
.SelectMenu-icon {
366+
.SelectMenu-icon--check {
372367
visibility: visible;
373368
transition: transform 0.12s cubic-bezier(0, 0, 0.2, 1), visibility 0s linear;
374369
transform: scale(1);

0 commit comments

Comments
 (0)