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

tweak CSS to prevent height jump on focus/selection, fix #236 #237

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 17 additions & 7 deletions src/lib/Svelecte.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@
{#each selectedOptions as opt (opt[currentValueField])}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div class="sv-item--container" animate:flip={{duration: flipDurationMs }} onmousedown={e => e.preventDefault()}>
<div class="sv-item--wrap" class:is-multi={multiple}>
<div class="sv-item--wrap in-selection" class:is-multi={multiple}>
<div class="sv-item--content">{@html itemRenderer(opt, true)}</div>
</div>
{#if multiple}
Expand Down Expand Up @@ -1586,7 +1586,7 @@
{/if}
{:else if options_filtered.length === 0 && (!creatable || !input_value) || maxReached}
<div class="is-dropdown-row">
<div class="sv-item--wrap"><div class="sv-item--content">{listMessage}</div></div>
<div class="sv-item--wrap in-dropdown"><div class="sv-item--content">{listMessage}</div></div>
</div>
{/if}
</div>
Expand All @@ -1613,13 +1613,16 @@
/* stylable props */
/*
:root {
--sv-min-height: 30px;
--sv-min-height: 34px;
--sv-bg: #fff;
--sv-disabled-bg: #eee;
--sv-border: 1px solid #ccc;
--sv-border-radius: 4px;
--sv-selection-gap: 4px;
--sv-general-padding: 4px;
--sv-control-bg: var(--sv-bg);
--sv-selection-wrap-padding: 0px 3px 0px 4px;
--sv-selection-multi-wrap-padding: 0px 3px 0px 6px;
--sv-item-wrap-padding: 3px 3px 3px 6px;
--sv-item-selected-bg: #efefef;
--sv-item-btn-color: #000;
Expand Down Expand Up @@ -1674,7 +1677,7 @@
border: var(--sv-border, 1px solid #ccc);
border-radius: var(--sv-border-radius, 4px);
background-color: var(--sv-control-bg, var(--sv-bg, #fff));
min-height: var(--sv-min-height, 30px);
min-height: var(--sv-min-height, 34px);
}

.sv-control--selection {
Expand All @@ -1683,8 +1686,8 @@
align-items: center;
flex: 1;
min-width: 0;
gap: 4px;
padding: var(--sv-general-padding, 4px);
gap: var(--sv-selection-gap, 4px);
padding: var(--sv-selection-gap, var(--sv-general-padding, 4px));
min-height: 24px;
&.is-single {
flex-wrap: nowrap;
Expand All @@ -1697,11 +1700,18 @@
:global(.sv-item--wrap) {
display: flex;
min-width: 0;
padding: var(--sv-item-wrap-padding, 3px 3px 3px 6px);
}
:global(.sv-item--wrap.in-selection) {
padding: var(--sv-selection-wrap-padding, 0px 3px 0px 4px);
}
:global(.sv-item--wrap.is-multi) {
padding: var(--sv-selection-multi-wrap-padding, 0px 3px 0px 6px);
background-color: var(--sv-item-selected-bg, #efefef);
}
:global(.sv-item--wrap.in-dropdown) {
padding: var(--sv-item-wrap-padding, 3px 3px 3px 6px);
}

:global(.sv-item--content) {
overflow: hidden;
white-space: nowrap;
Expand Down
7 changes: 6 additions & 1 deletion src/routes/theme/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

# Theme

Component is (hopefully) fully themable. This is the only page on the website where you can toggle light/dark mode.
Component is (hopefully) fully themable.

When changing `--sv-min-height`, you may also need to tweak one or multiple of these properties:
`--sv-selection-wrap-padding`, `--sv-selection-multi-wrap-padding`, `--sv-item-wrap-padding`.

---

Expand Down Expand Up @@ -82,6 +85,8 @@ Component is (hopefully) fully themable. This is the only page on the website wh
--sv-general-padding: 4px;
--sv-control-bg: var(--sv-bg);
--sv-item-wrap-padding: 3px 3px 3px 6px;
--sv-selection-wrap-padding: 3px 3px 3px 4px;
--sv-selection-multi-wrap-padding: 3px 3px 3px 6px;
--sv-item-selected-bg: #626262;
--sv-item-btn-color: #ccc;
--sv-item-btn-color-hover: #ccc;
Expand Down
5 changes: 5 additions & 0 deletions src/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
}
.svelecte {
--sv-min-height: 40px;
/** because height is raised, this needed to be tweaked accordingly */
--sv-selection-wrap-padding: 3px 3px 3px 4px;
--sv-selection-multi-wrap-padding: 3px 3px 3px 6px;
}

.dark .svelecte {
Expand All @@ -186,6 +189,8 @@
--sv-general-padding: 4px;
--sv-control-bg: var(--sv-bg);
--sv-item-wrap-padding: 3px 3px 3px 6px;
--sv-selection-wrap-padding: 3px 3px 3px 4px;
--sv-selection-multi-wrap-padding: 3px 3px 3px 6px;
--sv-item-selected-bg: #626262;
--sv-item-btn-color: #ccc;
--sv-item-btn-color-hover: #ccc;
Expand Down