Skip to content

Commit

Permalink
Remove space from combobox single select (#3384)
Browse files Browse the repository at this point in the history
* When single select on combobox, remove the gap between the input and the selected value.

* ♻️ Updated spacing between options and input in Combobox

* 📝 Changeset

* Revert darkside update

* ♻️ Update darkside combobox

* :refactor: Make gap something we add, not remove for chips based on type

* Update .changeset/yellow-days-rhyme.md

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>

* :refactor: Only add margin-left when only-child

---------

Co-authored-by: Ken <ken.aleksander@gmail.com>
Co-authored-by: Ken <26967723+KenAJoh@users.noreply.github.com>
Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 29, 2024
1 parent 8c9b2e2 commit fa2904d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/yellow-days-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-react": patch
"@navikt/ds-css": patch
---

Combobox: Single-select now shows cursor closer to selected item.
11 changes: 9 additions & 2 deletions @navikt/core/css/darkside/form/combobox.darkside.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
}

.navds-combobox__selected-options {
gap: var(--__axc-combobox-wrapper-inner-padding);
gap: 0;
align-items: center;

& > li {
Expand All @@ -140,6 +140,10 @@
display: flex;
flex: 1;
}

&[data-type="multiple"] {
gap: var(--__axc-combobox-wrapper-inner-padding);
}
}

.navds-combobox__selected-options--no-bg {
Expand All @@ -161,7 +165,6 @@
border: none;
padding: 0;
margin: 0;
margin-left: var(--ax-spacing-1);
min-width: 10ch;
width: 100%;
height: var(--__axc-combobox-input-height);
Expand All @@ -171,6 +174,10 @@
outline: 0;
border: none;
}

.navds-combobox__selected-options > li:only-child > & {
margin-left: var(--ax-spacing-1);
}
}

.navds-combobox__input--hide-caret {
Expand Down
11 changes: 9 additions & 2 deletions @navikt/core/css/form/combobox.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
}

.navds-combobox__selected-options {
gap: var(--__ac-combobox-wrapper-inner-padding);
gap: 0;
align-items: center;
}

Expand All @@ -120,6 +120,14 @@
padding-left: 0.25rem;
}

.navds-combobox__selected-options[data-type="multiple"] {
gap: var(--__ac-combobox-wrapper-inner-padding);
}

.navds-combobox__selected-options > li:only-child > .navds-combobox__input {
margin-left: var(--a-spacing-1);
}

.navds-combobox__input-wrapper {
width: 100%;
}
Expand All @@ -129,7 +137,6 @@
border: none;
padding: 0;
margin: 0;
margin-left: var(--a-spacing-1);
min-width: 10ch;
width: 100%;
height: var(--__ac-combobox-input-height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ const SelectedOptions: React.FC<SelectedOptionsProps> = ({
const { value } = useInputContext();
const { isMultiSelect } = useSelectedOptionsContext();
return (
<Chips className="navds-combobox__selected-options" size={size}>
<Chips
className="navds-combobox__selected-options"
size={size}
data-type={isMultiSelect ? "multiple" : "single"}
>
{value.length === 0 || (isMultiSelect && selectedOptions.length)
? selectedOptions.map((option, i) => (
<Option key={option.label + i} option={option} />
Expand Down

0 comments on commit fa2904d

Please sign in to comment.