Show downwards arrow on SelectButton (#1521)

* Show downwards arrow on SelectButton

The arrow wasn't showing because the button linear-gradient background overrides the background-image for the arrow.

Select can't have pseudo-elements, so I had to add an extra div.

* Remove height definition

to fix text cutting off on Windows.

* Hide default arrow in light theme

to keep consistency with dark theme, where the arrow has to be custom due to the button gradient.

* Use alternative approach to prevent text getting cropped

and add height definition back again.

Co-Authored-By: Hikaru Y. <47855854+hikaru-y@users.noreply.github.com>

* Adjust arrow position for rtl

Co-authored-by: Hikaru Y. <47855854+hikaru-y@users.noreply.github.com>
This commit is contained in:
Matthias Metelka 2021-12-03 23:08:20 +01:00 committed by GitHub
parent 3015ddd2c1
commit 936323e430
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="ts"> <script lang="ts">
import { onMount, createEventDispatcher } from "svelte"; import { onMount, createEventDispatcher } from "svelte";
import { pageTheme } from "../sveltelib/theme"; import { pageTheme } from "../sveltelib/theme";
let rtl: boolean = window.getComputedStyle(document.body).direction == "rtl";
export let id: string | undefined = undefined; export let id: string | undefined = undefined;
let className = ""; let className = "";
@ -20,7 +21,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</script> </script>
<!-- svelte-ignore a11y-no-onchange --> <!-- svelte-ignore a11y-no-onchange -->
<select <select
tabindex="-1" tabindex="-1"
bind:this={buttonRef} bind:this={buttonRef}
@ -29,27 +29,53 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
class="{className} form-select" class="{className} form-select"
class:btn-day={!$pageTheme.isDark} class:btn-day={!$pageTheme.isDark}
class:btn-night={$pageTheme.isDark} class:btn-night={$pageTheme.isDark}
class:visible-down-arrow={$pageTheme.isDark} class:rtl
title={tooltip} title={tooltip}
on:change on:change
> >
<slot /> <slot />
</select> </select>
<div class="arrow" class:dark={$pageTheme.isDark} class:rtl />
<style lang="scss"> <style lang="scss">
@use "sass/button-mixins" as button; @use "sass/button-mixins" as button;
@include button.btn-day($with-hover: false);
@include button.btn-night($with-hover: false);
select { select {
height: var(--buttons-size); height: var(--buttons-size);
/* Long option name can create overflow */ /* Long option name can create overflow */
overflow-x: hidden; text-overflow: ellipsis;
/* Prevents text getting cropped on Windows */
padding: {
top: 0;
bottom: 0;
}
&.rtl {
direction: rtl;
/* Reversed Bootstrap values */
padding-left: 2.25rem;
padding-right: 0.75rem;
}
&.btn-day {
/* Hide default arrow for consistency */
background: var(--frame-bg);
}
} }
.visible-down-arrow { .arrow {
/* override the default down arrow */ top: 0;
right: 10px;
&.rtl {
left: 10px;
}
width: 15px;
height: 100%;
position: absolute;
pointer-events: none;
background: button.down-arrow(black) no-repeat right;
&.dark {
background-image: button.down-arrow(white); background-image: button.down-arrow(white);
} }
}
@include button.btn-day($with-hover: false);
@include button.btn-night($with-hover: false);
</style> </style>