Tagged: 

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #103848

    I need to color some list item in different colors.

    The preferred resut would be to color the background of the list item.

    I tried with color attribute (red or #e0e383 notations) but nothing changed nor in the background nor in the forground colors (I tested also in tour demo setting color=”red” in a smart-list-item with no result).

    I tried using style=”background-color: red;” and I obtain a strange result : instead of seeing the background in the red color I see a thin red color line above the item.

    How can I solve ?

    Tks

    The testcase

    <!DOCTYPE html>
    <html xmlns=”http://www.w3.org/1999/xhtml”&gt;
    <head>
    <title>DropDownList Overview</title>

    <meta charset=”utf-8″ />
    <meta http-equiv=”X-UA-Compatible” content=”IE=edge” />
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0″ />

    <link rel=”stylesheet” type=”text/css” href=”../../../source/styles/smart.default.css” />
    <link rel=”stylesheet” type=”text/css” href=”../../styles/demos.css” />

    <link rel=”stylesheet” type=”text/css” href=”styles.css” />
    <script src=”index.js”></script>

    </head>
    <body class=”viewport”>

    <smart-drop-down-list>
    <smart-list-item style=”background-color: red;”>Item 1</smart-list-item>
    <smart-list-item>Item 2</smart-list-item>
    <smart-list-item>Item 3</smart-list-item>
    </smart-drop-down-list>
    <!– scripts –>
    <script src=”../../../source/modules/smart.dropdownlist.js”></script>
    <script src=”index.js”></script>

    </body>
    </html>

     

    #103853

    Hi,

    Add the style to the smart-list-item-container class.
    Give a class name to the desired list item and then apply a style like this:
    .bg-red .smart-list-item-container {
    background-color: red

    }

    See a demo here: https://codepen.io/dkeamcaksoem/pen/KKRJNZB

     

    Best Regards,
    Svetoslav Borislavov

    Smart UI Team
    https://www.htmlelements.com/

    #103858

    Tks for the solution, however I don’t know, a priori, the color I should use and then is quite difficult to define all needed classes.

    Is it possible to solve it using a style attribute (I can generate it at runtime) ?

    The color attribute what is usefull for ?

    Tks

     

    #103862

    Hi,

    You can set the style programmatically. Have a look at this example: https://codepen.io/dkeamcaksoem/pen/KKRJNZB

    or

    You can set a class for the list of items that you want to edit and use this class to select their inner element in the querySelectorAll.

    Example: querySelectorAll(‘.my-items .smart-list-item-container’)

    Best Regards,
    Svetoslav Borislavov

    Smart UI Team
    https://www.htmlelements.com/

    #103863

    Tks but this is not a solution in my environment :

    • my page is generated at runtime and then I can’t know a priori how many dropdown list I’ve, nor the id of each, nor how many items in each dropdown list, nor the color of each one and then I can’t use a js to do the job
    • not all items should be colored and each one could have its own color

    The best solution, if possible, shoud be

    <smart-list-item style=”background-color : myCololor;”> or something like that I can generate in a single shot.

    Tks

    #103865
    admin
    Keymaster

    Hi tbettinazzi,

    If you wish, you can create a function which styles a listbox and you can pass a listbox instance as a function parameter. Unfortunately, inline styles like that are not supported.

    Best regards,
    Peter Stoev

    Smart UI Team
    https://www.htmlelements.com/

    #103906

    Another question

    is it possible to set the classes of single items by dataSource ?

    Could You provide an example ?

    Tks

    #103908

    Hi,

    It is not possible to set classes in the dataSource.

    If you have any additional questions, do not hesitate to contact us!

    Best Regards,
    Svetoslav Borislavov

    Smart UI Team
    https://www.htmlelements.com/

    #103909

    Tks for your answer, however it seems that loading data from a dataSource is faster than create many <smart-list-items> and than I’m in an impasse :

    • if I use a dataSource I loose the coloration features I need
    • if I use <smart-list-items> I get poor preformances when I’ve large dropdown list

    Could You suggest a way to solve that problem ?

    Tks

    P.S. : Is there some url location where I can see what’s allowed in dataSource and what’s not ?

    #103914

    Hi,

    You can do the following:

    1. Set a dataSource with the items and in the object, you can add a property for the class
    2. ForEach the dataSource and for each item, you can get the relevant element and apply the element’s class

    Please look at the demo here: https://codepen.io/svetoslavb04/pen/OJEJXbe

    Hope this helps!

    Best Regards,
    Svetoslav Borislavov

    Smart UI Team
    https://www.htmlelements.com/

    #103915

    Tks, more or less solved.

    I still have a problem, when the dropdown list opens I see the following effects :

    • all elements have the correct height (setted by a class) but the last one which is larger (eg 50px vs 20px)
    • down of the last element I’ve a lot of white space (more or less 50px)

    Here my css definitions :

    smart-drop-down-list {
    min-height: 35px;
    height: auto;
    }

    .smart-list-item-container img {
    width: 100%;
    height: 100%;
    }

    smart-list-item .smart-content,
    smart-list-item .smart-overlay,
    smart-list-item,
    smart-drop-down-list {
    height: 100px;
    }

    .smart-list-item-container .image-description {
    display: block;
    position: absolute;
    z-index: 99999;
    top: 0;
    left: 70%;
    }

    I can provide You a printScreen of the noisy effects.

    Tks

     

    #103918

    I reproduced at least aprtially the problem on Your example (but I was not able to save it).

    I simply added a new class.

    This is the modified css

    html, body { padding: 10px; }

    .bg-red .smart-list-item-container {
    background-color: red;
    }

    smart-drop-down-list {
    min-height: 35px;
    height: auto;
    width: 300px;
    }
    .elemento_list_item {
    height: 20px;
    }

    .elemento_list_item .smart-content {
    height: 20px;
    }

    And this is the modified js

     

    window.onload = () => {

    const dropDownList = document.querySelector(‘smart-drop-down-list’);
    dropDownList.dataSource = [
    { label: “WAM ROMANIA”, value: “AF”, class: ‘bg-red’ },
    { label: “WAM PRODUCT”, value: “AA” }
    ]

    dropDownList.dataSource.forEach(element => {
    const item = dropDownList.getItem(element.value)
    console.log(item);
    item.classList.add(“elemento_list_item”);
    item.classList.add(element.class);
    });

    }

     

    Tks

    #103920

    Hi,

    There is a property for the items’ height: ‘item-height’
    Could you, please look at the example: https://codepen.io/svetoslavb04/pen/OJEJXbe

    Best Regards,
    Svetoslav Borislavov

    Smart UI Team
    https://www.htmlelements.com/

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.