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

Improve checkable item markup #549

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions web/app/components/x/dropdown-list/checkable-item.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div
data-test-checkable-item
class="checkable-item checkmark-position--{{or @checkmarkPosition 'leading'}}
class="checkable-item
{{if this.countIsShown 'has-count'}}
checkmark-position--{{or @checkmarkPosition 'leading'}}
w-full items-center gap-2.5"
...attributes
>
Expand All @@ -25,7 +27,7 @@
{{/if}}
</div>

{{#if @count}}
{{#if this.countIsShown}}
<div class="grid">
<Hds::BadgeCount
data-test-x-dropdown-list-checkable-item-count
Expand Down
10 changes: 9 additions & 1 deletion web/app/components/x/dropdown-list/checkable-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ interface XDropdownListCheckableItemComponentSignature {
};
}

export default class XDropdownListCheckableItemComponent extends Component<XDropdownListCheckableItemComponentSignature> {}
export default class XDropdownListCheckableItemComponent extends Component<XDropdownListCheckableItemComponentSignature> {
/**
* Whether the item has a count to display.
* True if the count is defined, including if it's 0.
*/
protected get countIsShown(): boolean {
return this.args.count !== undefined;
}
}

declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
Expand Down
32 changes: 22 additions & 10 deletions web/app/styles/components/x/dropdown/list-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,33 @@

.checkable-item {
@apply grid;
grid-template-columns: 16px auto 60px;
grid-template-columns: 16px auto;
grid-template-areas: "check label";

&.checkmark-position--trailing {
grid-template-columns: auto 60px 16px;
grid-template-columns: auto 16px;
grid-template-areas: "label check";
}

.checkable-item-content {
@apply order-1;
}
&.has-count {
grid-template-columns: 16px auto 60px;
grid-template-areas: "check label count";

.checkable-item-count {
@apply order-2;
&.checkmark-position--trailing {
grid-template-areas: "label count check";
grid-template-columns: auto 60px 16px;
}
}

.check {
@apply order-3;
}
.checkable-item-content {
grid-area: label;
}

.checkable-item-count {
grid-area: count;
}

.check {
grid-area: check;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { hbs } from "ember-cli-htmlbars";
import { CheckmarkPosition } from "hermes/components/x/dropdown-list/checkable-item";

const ITEM = "[data-test-checkable-item]";
const CONTENT = "[data-test-checkable-item-content]";
const CHECK = "[data-test-x-dropdown-list-checkable-item-check]";
const COUNT = "[data-test-x-dropdown-list-checkable-item-count]";

Expand All @@ -30,6 +29,11 @@ module("Integration | Component | x/dropdown-list", function (hooks) {
/>
`);

assert
.dom(ITEM)
.doesNotHaveClass("has-count")
.hasStyle({ "grid-template-areas": '"check label"' });

assert.dom(CHECK).hasClass("invisible");
assert.dom("[data-test-x-dropdown-list-item-value]").hasText("foo");
assert.dom(COUNT).doesNotExist();
Expand All @@ -38,8 +42,14 @@ module("Integration | Component | x/dropdown-list", function (hooks) {

assert.dom(CHECK).hasClass("visible");

this.set("count", 1);
assert.dom(COUNT).hasText("1");
this.set("count", 0);

assert
.dom(ITEM)
.hasClass("has-count")
.hasStyle({ "grid-template-areas": '"check label count"' });

assert.dom(COUNT).hasText("0");
});

test("it can render the checkmark in a leading or trailing position", async function (this: XDropdownListCheckableItemTestContext, assert) {
Expand All @@ -49,7 +59,7 @@ module("Integration | Component | x/dropdown-list", function (hooks) {
<X::DropdownList::CheckableItem
@checkmarkPosition={{this.checkmarkPosition}}
@isSelected={{true}}
@count={{1}}
@count={{0}}
@value="foo"
/>
`);
Expand All @@ -59,7 +69,8 @@ module("Integration | Component | x/dropdown-list", function (hooks) {
.hasClass(
"checkmark-position--leading",
"default checkmark position is leading",
);
)
.hasStyle({ "grid-template-areas": '"check label count"' });

this.set("checkmarkPosition", "trailing");

Expand All @@ -70,8 +81,6 @@ module("Integration | Component | x/dropdown-list", function (hooks) {
"can render checkmark in trailing position",
);

assert.dom(CONTENT).hasStyle({ order: "1" });
assert.dom(COUNT).hasStyle({ order: "2" });
assert.dom(CHECK).hasStyle({ order: "3" });
assert.dom(ITEM).hasStyle({ "grid-template-areas": '"label count check"' });
});
});