-
Notifications
You must be signed in to change notification settings - Fork 4
Dropdown improvements #932
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: f6f7fd4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
10f0242
to
120c62d
Compare
53fc9e6
to
b49492f
Compare
f976acf
to
9c220e1
Compare
|
||
it('can be reset', async () => { | ||
it('can be reset after options are selected via click', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to accommodate "can be reset after options are selected programmatically" below.
This test was falsely passing before because Dropdown wasn't opened before its options were clicked.
expect(host.value).to.deep.equal(['one', 'two']); | ||
expect(tags?.length).to.equal(2); | ||
expect(tags?.[0]?.label).to.equal('One'); | ||
expect(tags?.[1]?.label).to.equal('Two'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tag assertions throughout.
@@ -170,9 +170,6 @@ export default class DropdownOption extends LitElement { | |||
this.#checkboxElementRef.value.checked = isSelected; | |||
} | |||
|
|||
// Prefixed with "private" because Dropdown uses it internally, to track the set of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't actually how Dropdown uses this event. I started rewriting the comment then realized that it didn't add much given it's only used by one method: #onOptionsSelectedChange()
.
@@ -35,12 +35,13 @@ it('is accessible', async () => { | |||
await expect(host).to.be.accessible(); | |||
}); | |||
|
|||
it('sets `value` to that of its selected options', async () => { | |||
it('can have selected options', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this test to accommodate more assertions.
f66e20c
to
27cfdc5
Compare
@@ -367,3 +342,56 @@ it('does not include in its `value` disabled options that are selected', async ( | |||
|
|||
expect(host.value).to.deep.equal([]); | |||
}); | |||
|
|||
it('only selects the first option with a matching value when multiple options have the same value and `value` is set', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
value
is set programmatically, only the first Dropdown Option with a matching value is now selected instead of every Dropdown Option with a matching value.
@@ -12,22 +12,40 @@ it('is accessible ', async () => { | |||
await expect(host).to.be.accessible(); | |||
}); | |||
|
|||
it('has a selected option label when an option is initially selected', async () => { | |||
it('can have a selected option', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this test to accommodate more assertions.
@@ -171,3 +264,33 @@ it('has no `formData` value when an option is selected that has no `value`', asy | |||
const formData = new FormData(form); | |||
expect(formData.get('name')).to.be.null; | |||
}); | |||
|
|||
it('does not submit its form when a tag is removed via Enter', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing a tag via Enter no longer submits the form
|
||
it('can be reset', async () => { | ||
it('can be reset after an option is selected via click', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to accommodate "can be reset after an option is selected programmatically" below.
expect(host.value).to.deep.equal(['one']); | ||
}); | ||
|
||
it('can be reset after an option is deselected via click', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gaps.
@@ -560,7 +560,6 @@ it('does not clear its filter when a tag is removed via Backspace', async () => | |||
</glide-core-dropdown>`, | |||
); | |||
|
|||
await aTimeout(0); // Wait for Floating UI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to wait for Floating UI. Awaiting sendKeys()
is enough.
@@ -782,6 +779,46 @@ it('clears its input field when made multiselect programmatically', async () => | |||
expect(input?.value).to.be.empty.string; | |||
}); | |||
|
|||
it('updates itself made single-select programmatically and an option is selected', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropdown's input field is now populated with the
label
of the selected Dropdown Option when filterable andmultiple
is set tofalse
programmatically.
@@ -1960,7 +1997,7 @@ it('shows an ellipsis when the label of its selected option is set programmatica | |||
option.label = 'x'.repeat(500); | |||
await host.updateComplete; | |||
|
|||
// Wait for the resize observer to do its thing. | |||
// Wait for the Resize Observer to do its thing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't make a different to me. Just made it the same as it is everywhere else.
@@ -77,21 +78,25 @@ it('selects options on click via mouse', async () => { | |||
|
|||
await aTimeout(0); // Wait for Floating UI | |||
await click(options[0]); | |||
await click(options[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selecting multiple options doesn't test anything additional.
}); | ||
|
||
it('selects no options when `value` is set programmatically to an empty string and some options have no `value`', async () => { | ||
it('only selects the first option when `value` is set programmatically and multiple options have the same `value`', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
value
is set programmatically, only the first Dropdown Option with a matching value is now selected instead of every Dropdown Option with a matching value
@@ -848,39 +946,6 @@ it('deselects an option when its tag is removed', async () => { | |||
expect(host.value).to.deep.equal(['two']); | |||
}); | |||
|
|||
it('deselects all but the last selected option when `multiple` is changed to `false` programmatically', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to dropdown.test.interactions.single.ts
next to the other tests that test changing from multiselect to single-select.
98cfa84
to
be05e07
Compare
expect(tagContainers?.length).to.equal(2); | ||
}); | ||
|
||
it('has overflow text when its tags are overflowing', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combined this test and the one above.
@@ -1436,77 +1460,42 @@ it('clicks its primary button when `click()` is called', async () => { | |||
expect(event instanceof PointerEvent).to.be.true; | |||
}); | |||
|
|||
it('adds the `value` of a programmatically enabled option to its `value`', async () => { | |||
it('updates itself when a selected option is disabled programmatically', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to accommodate more assertions.
be05e07
to
b9aa414
Compare
}); | ||
|
||
it('sets `aria-selected` when an option is deselected programmatically', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard to tell from the diff. I removed this test and added its assertion to "deselects an option when it is deselected programmatically". Similar for the tests below.
b9aa414
to
f6f7fd4
Compare
🚀 Description
Another round of Dropdown bugfixes before I move on to generalizing Menu:
Additionally:
📋 Checklist
🔬 Testing
Dropdown Option's
selected
attribute is no longer reflected to match native and to resolve a bug whenreset()
is called on its form