Skip to content

Commit

Permalink
Fix popover width and improve dropdown list truncation (#542)
Browse files Browse the repository at this point in the history
* Fix popover width

* Improve truncation logic

* Update checkable-item.hbs

* Update test selectors and remove old CSS
  • Loading branch information
jeffdaley authored Jan 12, 2024
1 parent 400e761 commit f645a23
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
23 changes: 14 additions & 9 deletions web/app/components/x/dropdown-list/checkable-item.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div
data-test-checkable-item
class="checkable-item checkmark-position--{{or @checkmarkPosition 'leading'}}
flex w-full items-center gap-2.5"
w-full items-center gap-2.5"
...attributes
>

Expand All @@ -12,22 +12,27 @@
class="check {{if @isSelected 'visible' 'invisible'}}"
/>

<div data-test-checkable-item-content class="checkable-item-content w-full">
<div
data-test-checkable-item-content
class="checkable-item-content w-full overflow-hidden"
>
{{#if (has-block "default")}}
{{yield}}
{{else}}
<div class="x-dropdown-list-item-value">
<div data-test-x-dropdown-list-item-value class="truncate">
{{@value}}
</div>
{{/if}}
</div>

{{#if @count}}
<Hds::BadgeCount
data-test-x-dropdown-list-checkable-item-count
@text="{{@count}}"
@size="small"
class="x-dropdown-list-item-count checkable-item-count"
/>
<div class="grid">
<Hds::BadgeCount
data-test-x-dropdown-list-checkable-item-count
@text="{{@count}}"
@size="small"
class="checkable-item-count ml-auto"
/>
</div>
{{/if}}
</div>
6 changes: 4 additions & 2 deletions web/app/components/x/dropdown-list/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
@offset={{@offset}}
@disableClose={{@disableClose}}
@matchAnchorWidth={{@matchAnchorWidth}}
class="{{unless (eq @placement null) 'hermes-popover'}} x-dropdown-list"
class="x-dropdown-list
{{unless (eq @placement null) 'hermes-popover'}}
{{if this.inputIsShown 'has-input'}}"
data-test-x-dropdown-list-content
{{will-destroy this.onDestroy}}
...attributes
Expand Down Expand Up @@ -96,7 +98,7 @@
{{will-destroy this.resetFilteredItems}}
{{dismissible dismiss=f.hideContent related=f.anchor}}
id="x-dropdown-list-container-{{f.contentID}}"
class="x-dropdown-list-container {{if this.inputIsShown 'has-input'}}"
class="x-dropdown-list-container"
role={{if this.inputIsShown "combobox"}}
>
{{#if @isLoading}}
Expand Down
13 changes: 5 additions & 8 deletions web/app/styles/components/x/dropdown/list-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@
}
}

.x-dropdown-list-item-value {
@apply w-full truncate whitespace-nowrap;
}

.x-dropdown-list-item-count {
@apply ml-8 shrink-0;
}

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

&.checkmark-position--trailing {
grid-template-columns: auto 60px 16px;

.checkable-item-content {
@apply order-1;
}
Expand Down
6 changes: 3 additions & 3 deletions web/tests/integration/components/header/toolbar-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ module("Integration | Component | header/toolbar", function (hooks) {
await click("[data-test-facet-dropdown-trigger='Status']");

assert.deepEqual(
findAll(".x-dropdown-list-item-value")?.map((el) =>
el.textContent?.trim()
findAll("[data-test-x-dropdown-list-item-value]")?.map(
(el) => el.textContent?.trim(),
),
["Approved", "In-Review", "In Review", "Obsolete", "WIP"],
"Unsupported statuses are filtered out"
"Unsupported statuses are filtered out",
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module("Integration | Component | x/dropdown-list", function (hooks) {
`);

assert.dom(CHECK).hasClass("invisible");
assert.dom(".x-dropdown-list-item-value").hasText("foo");
assert.dom("[data-test-x-dropdown-list-item-value]").hasText("foo");
assert.dom(COUNT).doesNotExist();

this.set("isSelected", true);
Expand Down

0 comments on commit f645a23

Please sign in to comment.