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

feat: add no-vertical-overlap prop to vaadin-select #7492

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions packages/select/src/vaadin-lit-select.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small thing I noticed is that for combo box, date picker, time picker there's a few pixels of offset between the input and the overlay. With select there is no offset between the value button and the overlay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I had it done locally but forgot to commit the file 🤦🏻

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now 👍

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Select extends SelectBaseMixin(ElementMixin(ThemableMixin(PolylitMixin(Lit
.renderer="${this.renderer || this.__defaultRenderer}"
?phone="${this._phone}"
theme="${this._theme}"
?no-vertical-overlap="${this.noVerticalOverlap}"
@opened-changed="${this._onOpenedChanged}"
@vaadin-overlay-open="${this._onOverlayOpen}"
></vaadin-select-overlay>
Expand Down
8 changes: 8 additions & 0 deletions packages/select/src/vaadin-select-base-mixin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ export declare class SelectBaseMixinClass {
*/
readonly: boolean;

/**
* Defines whether the overlay should overlap the target element
* in the y-axis, or be positioned right above/below it.
*
* @attr {boolean} no-vertical-overlap
*/
noVerticalOverlap: boolean;

/**
* Requests an update for the content of the select.
* While performing the update, it invokes the renderer passed in the `renderer` property.
Expand Down
11 changes: 11 additions & 0 deletions packages/select/src/vaadin-select-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ export const SelectBaseMixin = (superClass) =>
reflectToAttribute: true,
},

/**
* Defines whether the overlay should overlap the target element
* in the y-axis, or be positioned right above/below it.
*
* @attr {boolean} no-vertical-overlap
*/
noVerticalOverlap: {
type: Boolean,
value: false,
},

/** @private */
_phone: Boolean,

Expand Down
1 change: 1 addition & 0 deletions packages/select/src/vaadin-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class Select extends SelectBaseMixin(ElementMixin(ThemableMixin(PolymerElement))
with-backdrop="[[_phone]]"
phone$="[[_phone]]"
theme$="[[_theme]]"
no-vertical-overlap$="[[noVerticalOverlap]]"
on-vaadin-overlay-open="_onOverlayOpen"
></vaadin-select-overlay>

Expand Down
29 changes: 29 additions & 0 deletions packages/select/test/select.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,35 @@ describe('vaadin-select', () => {
expect(changeSpy.callCount).to.equal(1);
});
});

describe('no-vertical-overlap', () => {
it('should overlap the input by default', async () => {
select.opened = true;
await nextUpdate(select);
const overlayRect = select._overlayElement.getBoundingClientRect();
const inputRect = select._inputContainer.getBoundingClientRect();
expect(overlayRect.top).to.be.equal(inputRect.top);
});

it('should toggle the `no-vertical-overlap` atrribute in the overlay element', async () => {
DiegoCardoso marked this conversation as resolved.
Show resolved Hide resolved
select.noVerticalOverlap = true;
await nextUpdate(select);
expect(select._overlayElement.hasAttribute('no-vertical-overlap')).to.be.true;

select.noVerticalOverlap = false;
await nextUpdate(select);
expect(select._overlayElement.hasAttribute('no-vertical-overlap')).to.be.false;
});

it('should not overlap the input when overlay is opened', async () => {
select.noVerticalOverlap = true;
select.opened = true;
await nextUpdate(select);
const overlayRect = select._overlayElement.getBoundingClientRect();
const inputRect = select._inputContainer.getBoundingClientRect();
expect(overlayRect.top).to.be.equal(inputRect.bottom);
});
});
});

describe('with value', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/select/theme/lumo/vaadin-select-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ const selectOverlay = css`
justify-content: flex-end;
}

:host([no-vertical-overlap][top-aligned]) [part='overlay'] {
margin-block-start: var(--lumo-space-xs);
}

:host([no-vertical-overlap][bottom-aligned]) [part='overlay'] {
margin-block-end: var(--lumo-space-xs);
}

:host([theme~='align-left']) {
text-align: left;
}
Expand Down
Loading