Skip to content

Commit 6af535d

Browse files
committed
fix(core): update select size handling and improve layout
- Adjusted the CSS variables for size and gap to enhance layout consistency. - Updated the size property logic in the Select component to correctly reflect the intended size. - Enhanced tests to verify proper rendering of options without overflow and ensure no blank space after visible rows. Signed-off-by: Cory Rylan <crylan@nvidia.com>
1 parent f66cab0 commit 6af535d

7 files changed

Lines changed: 57 additions & 19 deletions

File tree

Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

‎projects/core/.visual/select.png‎

Lines changed: 2 additions & 2 deletions
Loading

‎projects/core/src/select/select.css‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@
1010
--border-radius: var(--nve-ref-border-radius-sm);
1111
--border: var(--nve-ref-border-width-md) solid transparent;
1212
--border-bottom: var(--border);
13+
--gap: var(--nve-ref-space-xxs);
1314
--cursor: pointer;
1415
--font-weight: normal;
1516
--text-align: start;
1617
--scroll-height: 50vh;
17-
--_input-background: var(--background);
18-
--_icon-color: var(--color);
1918
--width: 100%;
2019
--control-width: var(--width);
2120
--max-width: 100%;
2221
--min-width: fit-content;
22+
--_input-background: var(--background);
23+
--_icon-color: var(--color);
24+
--_gap: var(--gap);
25+
--size: 1;
26+
--_row-height: calc(var(--height) *var(--size) +var(--gap) * (var(--size) - 1));
27+
--_height: calc(var(--_row-height) +var(--nve-ref-border-width-md) * 2);
2328
contain: initial;
2429
width: var(--width);
2530
max-width: var(--max-width);
@@ -35,7 +40,11 @@
3540
}
3641

3742
[input] {
38-
height:var(--height);
43+
scroll-behavior: smooth;
44+
scrollbar-color:color-mix(in oklab,var(--nve-sys-scrollbar-thumb-color) 100%, currentColor 20%)
45+
var(--nve-sys-scrollbar-track-color);
46+
scrollbar-width:var(--nve-sys-scrollbar-width);
47+
height:var(--_height);
3948
background:var(--background);
4049
border:var(--border);
4150
border-bottom:var(--border-bottom);
@@ -64,7 +73,7 @@
6473
cursor:var(--cursor) !important;
6574
font-weight:var(--font-weight) !important;
6675
text-align:var(--text-align) !important;
67-
height:var(--height) !important;
76+
height:var(--_height) !important;
6877
width:100%!important;
6978
border:0!important;
7079
background: none !important;
@@ -94,7 +103,7 @@
94103
:host(:state(multiple)) .tags {
95104
width: fit-content;
96105
display: flex;
97-
gap:var(--nve-ref-space-xxs);
106+
gap:var(--gap);
98107
}
99108

100109
:host(:state(multiple)) .tags-label {
@@ -130,10 +139,6 @@
130139
opacity:0!important;
131140
}
132141

133-
:host(:state(size)) {
134-
--height:calc(var(--nve-ref-size-800) *var(--size));
135-
}
136-
137142
:host(:state(size)) [input] {
138143
overflow: auto;
139144
display: block;
@@ -184,6 +189,7 @@ nve-dropdown {
184189

185190
nve-menu {
186191
--max-height:var(--scroll-height);
192+
--gap:var(--_gap);
187193
}
188194

189195
nve-menu-item {

‎projects/core/src/select/select.test.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,39 @@ describe(`${Select.metadata.tag}: size`, () => {
700700
});
701701

702702
it('should set --size property',()=>{
703-
expect(getComputedStyle(element).getPropertyValue('--size')).toBe('3.75');// size (3) + 0.75 buffer
703+
expect(getComputedStyle(element).getPropertyValue('--size')).toBe('3');
704+
});
705+
706+
it('should show all rows without overflow',async()=>{
707+
constselect=fixture.querySelector('select')asHTMLSelectElement;
708+
for(letoptionNumber=6;optionNumber<=10;optionNumber++){
709+
constoption=document.createElement('option');
710+
option.value=`${optionNumber}`;
711+
option.textContent=`Option ${optionNumber}`;
712+
select.append(option);
713+
}
714+
select.size=10;
715+
awaitelementIsStable(element);
716+
717+
constinput=element.shadowRoot.querySelector<HTMLElement>('[input]')asHTMLElement;
718+
constitems=element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag)asNodeListOf<MenuItem>;
719+
constinputBottom=
720+
input.getBoundingClientRect().bottom-Number.parseFloat(getComputedStyle(input).borderBottomWidth);
721+
constlastItemBottom=items[items.length-1].getBoundingClientRect().bottom;
722+
723+
expect(input.scrollTop).toBe(0);
724+
expect(lastItemBottom).toBeCloseTo(inputBottom,5);
725+
});
726+
727+
it('should not leave blank space after the visible rows',()=>{
728+
constinput=element.shadowRoot.querySelector<HTMLElement>('[input]');
729+
constitems=element.shadowRoot.querySelectorAll<MenuItem>(MenuItem.metadata.tag);
730+
constinputBottom=
731+
input.getBoundingClientRect().bottom-Number.parseFloat(getComputedStyle(input).borderBottomWidth);
732+
constlastVisibleItemBottom=items[2].getBoundingClientRect().bottom;
733+
734+
expect(input.scrollTop).toBe(0);
735+
expect(lastVisibleItemBottom).toBeCloseTo(inputBottom,5);
704736
});
705737

706738
it('should not render tags when using multiple with size',async()=>{

‎projects/core/src/select/select.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class Select extends Control {
233233
super.updated(props);
234234
if(this.#select?.size&&this.#select?.size!==0){
235235
this._internals.states.add('size');
236-
this.style.setProperty('--size',`${this.#select?.size+0.75}`);
236+
this.style.setProperty('--size',`${this.#select.size}`);
237237
}else{
238238
this._internals.states.delete('size');
239239
this.style.removeProperty('--size');

0 commit comments

Comments
 (0)