Skip to content

Commit 3c72e54

Browse files
committed
Merge remote-tracking branch 'origin/lab' into lab
2 parents be2c627 + 56b7cc6 commit 3c72e54

File tree

11 files changed

+491
-208
lines changed

11 files changed

+491
-208
lines changed

index.html

Lines changed: 149 additions & 66 deletions
Large diffs are not rendered by default.

src/base/dropdown-element.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export class DropdownElement extends SgdsElement {
8989
//working
9090
this.dropdownConfig = {
9191
placement: "bottom-start",
92-
strategy: "fixed",
9392
modifiers: !this.noFlip
9493
? this.modifierOpt
9594
: [
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
.combobox .dropdown-menu {
2+
min-width: 100%;
3+
}
4+
15
.sgds.combobox .form-control-icon {
26
align-items: center;
3-
display: flex;
7+
/* display: flex;
48
font-size: 1rem;
59
height: 3rem;
610
justify-content: center;
711
position: absolute;
812
width: 3rem;
9-
z-index: 4;
13+
z-index: 4; */
1014
}
15+
1116
.sgds.combobox {
1217
display: flex;
1318
flex-wrap: wrap;
@@ -16,16 +21,25 @@
1621
position: relative;
1722
width: -webkit-fill-available;
1823
width: -moz-available;
24+
1925
}
20-
.sgds.combobox .dropdown-toggle {
21-
width: 100%;
22-
}
23-
.sgds.combobox > .dropdown-menu {
24-
min-width: 100%;
26+
27+
28+
.dropdown-menu {
29+
max-height: 10rem;
30+
overflow-y: auto;
31+
overflow-x: hidden;
32+
box-sizing: border-box;
2533
}
34+
35+
/* .sgds.combobox .dropdown-toggle {
36+
width: 100%;
37+
} */
38+
2639
.form-control-icon {
2740
bottom: 0;
2841
}
42+
2943
.combobox-caret {
3044
color: var(--sgds-form-color-default);
3145
}

src/components/ComboBox/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { SgdsComboBox } from "./sgds-combo-box";
22
import { register } from "../../utils/ce-registry";
3+
import SgdsComboBoxItem from "./sgds-combo-box-item";
34

45
register("sgds-combo-box", SgdsComboBox);
56

67
declare global {
78
interface HTMLElementTagNameMap {
89
"sgds-combo-box": SgdsComboBox;
10+
"sgds-combo-box-item": SgdsComboBoxItem;
911
}
1012
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
:host([active]) .dropdown-item {
2+
background-color: var(--sgds-form-primary-bg-translucent, rgba(90, 66, 192, 0.1));
3+
}
4+
5+
.dropdown-item .normal-item-content {
6+
display: flex;
7+
align-items: center;
8+
justify-content: space-between;
9+
10+
}
11+
12+
:host([active]) .dropdown-item .normal-item-content {
13+
color: var(--sgds-primary-bg);
14+
}
15+
16+
:host([active]) .dropdown-item .normal-item-content sgds-icon {
17+
color: var(--sgds-primary-bg);
18+
fill: var(--sgds-primary-bg);
19+
}
20+
21+
.dropdown-item {
22+
padding: var(--sgds-dropdown-item-padding-y, 0.5rem) var(--sgds-dropdown-item-padding-x, 1rem);
23+
24+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { html, nothing } from "lit";
2+
import { property } from "lit/decorators.js";
3+
import { classMap } from "lit/directives/class-map.js";
4+
import SgdsElement from "../../base/sgds-element";
5+
import SgdsIcon from "../Icon/sgds-icon";
6+
import SgdsCheckbox from "../Checkbox/sgds-checkbox";
7+
import comboBoxItemStyles from "./sgds-combo-box-item.css";
8+
9+
export class SgdsComboBoxItem extends SgdsElement {
10+
static dependencies = {
11+
"sgds-icon": SgdsIcon,
12+
"sgds-checkbox": SgdsCheckbox
13+
};
14+
15+
static styles = [comboBoxItemStyles];
16+
/** when true, sets the active stylings */
17+
@property({ type: Boolean }) active = false;
18+
19+
/** Disables the Item */
20+
@property({ type: Boolean, reflect: true }) disabled = false;
21+
22+
/** If true, this item is rendered as a checkbox item */
23+
@property({ type: Boolean, reflect: true }) checkbox = false;
24+
25+
connectedCallback(): void {
26+
super.connectedCallback();
27+
this.setAttribute("role", "menuitem");
28+
this.setAttribute("aria-disabled", `${this.disabled}`);
29+
}
30+
31+
private _handleNonCheckboxClick() {
32+
if (!this.checkbox) {
33+
this.active = true;
34+
this.dispatchEvent(
35+
new CustomEvent("sgds-combo-box-item-select", {
36+
detail: { active: this.active },
37+
bubbles: true,
38+
composed: true
39+
})
40+
);
41+
}
42+
}
43+
44+
private _handleCheckboxChange(e: Event) {
45+
const checkbox = e.target as HTMLInputElement;
46+
this.active = checkbox.checked;
47+
48+
this.dispatchEvent(
49+
new CustomEvent("sgds-combo-box-item-select", {
50+
detail: { active: this.active },
51+
bubbles: true,
52+
composed: true
53+
})
54+
);
55+
}
56+
57+
render() {
58+
const classes = {
59+
disabled: this.disabled,
60+
active: this.active,
61+
checkbox: this.checkbox
62+
};
63+
64+
return html`
65+
<div
66+
class="dropdown-item ${classMap(classes)}"
67+
tabindex=${this.disabled ? "-1" : "0"}
68+
@click=${!this.checkbox ? this._handleNonCheckboxClick : null}
69+
>
70+
${this.checkbox
71+
? html`
72+
<sgds-checkbox
73+
.checked=${this.active}
74+
.disabled=${this.disabled}
75+
@sgds-change=${this._handleCheckboxChange}
76+
>
77+
<slot></slot>
78+
</sgds-checkbox>
79+
`
80+
: html`
81+
<div class="normal-item-content">
82+
<slot></slot>
83+
${this.active
84+
? html`
85+
<div>
86+
<sgds-icon name="check"></sgds-icon>
87+
</div>
88+
`
89+
: nothing}
90+
</div>
91+
`}
92+
</div>
93+
`;
94+
}
95+
}
96+
97+
export default SgdsComboBoxItem;

0 commit comments

Comments
 (0)