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

Progress Bar Label Becomes Unreadable at Low Values #477

Open
DaveL17 opened this issue Oct 23, 2023 · 3 comments
Open

Progress Bar Label Becomes Unreadable at Low Values #477

DaveL17 opened this issue Oct 23, 2023 · 3 comments
Labels
component New or changes to components enhancement New feature or request

Comments

@DaveL17
Copy link

DaveL17 commented Oct 23, 2023

What package has an issue

@svelteuidev/core

A clear and concise description of what the bug is

When the value of a progress bar becomes very low (counting down to zero), the label can become obscured/unreadable.

Suggested fix: when the value becomes low--say 10%--have the label display to the right of the bar in the "vacated" space.

In which browser(s) did the problem occur?

Firefox, Chrome, Safari

Steps To Reproduce

Literally, simply display a progress bar with a value like 5.

Screenshot 2023-10-23 at 4 05 17 PM

Do you know how to fix the issue

No

Are you willing to participate in fixing this issue and create a pull request with the fix

No

Relevant Assets

No response

@DaveL17 DaveL17 added the bug Something isn't working label Oct 23, 2023
@BeeMargarida BeeMargarida added the component New or changes to components label Oct 24, 2023
@BeeMargarida
Copy link
Member

This was mentioned in the discord server, I'll leave this open since it's a problem and perhaps we should hide the label or move it outside. Here's a possible workaround that shows the label outside when the value is small:

<script lang="ts">
  import { Flex, Progress, SvelteUIProvider, Text } from "@svelteuidev/core";

  let value = 5;

  function increase() {
    if (value === 100) {
      return;
    }
    value += 5;
  }

  function decrease() {
    if (value === 0) {
      return;
    }
    value -= 5;
  }

  $: label = value <= 5 ? '' : `${value}%`;
</script>

<SvelteUIProvider>
  <Flex>
    <!-- This is necessary since Progress has a position relative, we need
     to set the width of the parent -->
    <div style="width: 100%">
      <Progress bind:value size="lg" {label} />
    </div>
    {#if value <= 5}
      <Text size={12} ml="4">{`${value}%`}</Text>
    {/if}
  </Flex>

  <div style="margin-top: 50px">
    <button on:click={increase}>Increase</button>
    <button on:click={decrease}>Decrease</button>
  </div>
</SvelteUIProvider>

Stackblitz with this: https://stackblitz.com/edit/vitejs-vite-6zjfau?file=src%2FApp.svelte

@BeeMargarida BeeMargarida added enhancement New feature or request and removed bug Something isn't working labels Nov 3, 2023
@DaveL17
Copy link
Author

DaveL17 commented Nov 3, 2023

Here's an html/js/css example of what I think would be ideal (the behavior, not necessarily the style). Have the label inside right until the lowest levels and then have it outside right. Rough code below.

Screenshot 2023-11-03 at 5 17 17 PM Screenshot 2023-11-03 at 5 16 47 PM

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Progress Bar</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        html {
            font-family: "Lato Heavy", sans-serif;
        }
        .container {
            border: solid 1px black;
            border-radius: 6px;
            height: 24px;
            box-shadow: inset #333333 1px 1px 8px;
            width: 100%;
        }
        .bar {
            background-color: #009fff;
            border-radius:3px;
            float: left;
            height:24px;
            width:90%;
        }
        .value {
            color: slategray;
            float: right;
            padding: 3px;
            position: relative;
        }
    </style>
</head>
<body>
    <div>
        <p>Battery Level</p>
        <div class="container">
            <div class="bar">
                <div class="value" id="barValue">90%</div>
                <script>
                    let value = 90
                    let barText = document.getElementById("barValue");
                    if (value >= 10) {
                        barText.setAttribute("style", "right: 0px; color: white");
                    } else {
                        barText.setAttribute("style", "right: -30px; color: slategrey");
                    }
                </script>
            </div>
        </div>
    </div>
</body>
</html>

@DaveL17
Copy link
Author

DaveL17 commented Nov 9, 2023

This is fixed and will be included in an upcoming PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component New or changes to components enhancement New feature or request
Projects
Status: Next
Development

No branches or pull requests

2 participants