0

I have a LWC, there is a section which comprises of filters. Most of them are standard lightning-inputs, but two of them, are custom lookup components. The problem is, I can't find a way to make them align and look the same.. even if internally it is applying slds css classes (to some extent). This is how it's looking right now:

enter image description here

As you can see, every lightning input is aligned correctly, but then the two lookup component's inputs are wider and with less space between the label and the input.

This is the lookup html code:

<template>
<label if:true={label} class={getLabelClass} for="combobox">
    <abbr if:true={required} title="required" class="slds-required">*</abbr>
    {label}
</label>
<div class={getContainerClass}>
    <div class={getDropdownClass} aria-expanded={hasResults} aria-haspopup="listbox" role="combobox">
        <!-- Search input start -->
        <div class={getComboboxClass} role="none">
            <!-- Text input -->


            <template if:false={useInput}>

                <slot 
                aria-autocomplete="list"
                aria-controls="listbox"
                role="textbox"
                id="combobox"
                onchange={handleInput}
                oninput={handleInput}
                onkeydown={handleKeyDown}
                onslotchange={handleSlotChange}
                ></slot>
            </template>
            <template if:true={useInput}>
                <input onfocus={handleFocus}
                       onblur={handleBlur} 
                       oninput={handleInput} 
                       class="slds-input" 
                       style="color: black;"/>
            </template>    
              
           
                <template if:true={isLookup}>
                    <!-- Search icon -->
                      
                    <lightning-icon
                    icon-name="utility:search"
                    size="x-small"
                    alternative-text="Search icon"
                    class={getSearchIconClass}
                    ></lightning-icon>
                    
                    <button
                    title="Remove selected option"
                    type="button"
                    onclick={handleClearSelection}
                    class={getClearSelectionButtonClass}
                    disabled={disabled}
                    >
                    <lightning-icon
                    icon-name="utility:close"
                    size="x-small"
                    alternative-text="Remove selected option"
                    class="slds-button__icon"
                    ></lightning-icon>
                    </button>
                </template>
            </div>
       
        <!-- Search input end -->
        
        <!-- Result list box start -->
        <div
        id="listbox"
        role="listbox"
        >
        <ul class={getListboxClass} role="presentation">
                <!-- Spinner to display when waiting for results of search -->
                <div if:true={loading}>
                    <lightning-spinner variant="brand" alternative-text="Loading" size="small"></lightning-spinner>
                </div>

                <template for:each={_searchResults} for:item="result">
                    <li data-id={result.id} onmousedown={handleResultClick} class="slds-listbox__item" key={result.id} role="presentation">
                        <div class="slds-media slds-listbox__option slds-listbox__option_plain slds-media_small" role="option">
                            <c-lookup-result template={_template} result={result}></c-lookup-result>
                        </div>
                    </li>
                </template>
                <!-- Result list end -->

                <!-- No results start -->
                <template if:false={hasResults}>
                    <li role="presentation">
                        <span class="slds-media slds-listbox__option_entity" role="option">
                            <span if:false={loading} class="slds-media__body">No results.</span>
                            <span if:true={loading} class="slds-media__body">Loading...</span>
                        </span>
                    </li>
                </template>
                <!-- No results end -->

            </ul>
        </div>
        <!-- Result list box end -->
    </div>
</div>

</template>

In my case, "useInput" is true

These are the getters:

    get getContainerClass() {
    let css = 'slds-combobox_container'; // slds-has-inline-listbox  // sacado porque moleasta
    if (this._hasFocus && this.hasResults) {
        css += 'slds-has-input-focus ';
    }
    if (this.errors.length > 0) {
        css += 'has-custom-error';
    }
    return css;
}

get getDropdownClass() {
    let css = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click ';
    if (this._hasFocus && (this._currentConfig || this.loading)) {
        css += 'slds-is-open';
    }
    return css;
}

get getComboboxClass() {
    let css = 'slds-combobox__form-element slds-input-has-icon ';
    return css += this.hasSelection() ? 'slds-input-has-icon_left-right' : 'slds-input-has-icon_right';
}

get getListboxClass() {
    return (
        'slds-listbox slds-listbox_vertical slds-dropdown slds-dropdown_fluid ' +
        (this.scrollAfterNItems ? 'slds-dropdown_length-with-icon-' + this.scrollAfterNItems : '')
    );
}

get getClearSelectionButtonClass() {
    return (
        'slds-button slds-button_icon slds-input__icon slds-input__icon_left ' +
        (this.hasSelection() ? '' : 'slds-hide')
    );
}

get getSearchIconClass() {
    let css = 'slds-input__icon slds-input__icon_right ';
    if (!this.isMultiEntry) {
        css += this.hasSelection() ? 'slds-hide' : '';
    }
    return css;
}

get getLabelClass() {
    return this.variant === VARIANT_LABEL_HIDDEN
        ? 'slds-form-element__label slds-assistive-text'
        : 'slds-form-element__label';
}

get input() {
    return this._input;
}

This is my code for what's on the image:

    <template if:true={filters}>
    <div class="slds-grid slds-gutters">
        <div class="slds-col slds-size_1-of-2">
            <c-lwc-filter filter={filters.Nombre} input-variant="label-inline"></c-lwc-filter>
            <c-lwc-filter filter={filters.Codigo} input-variant="label-inline"></c-lwc-filter>
            <c-lwc-filter filter={filters.CodigoFabricante} input-variant="label-inline"></c-lwc-filter>
        </div>
        <div class="slds-col slds-size_1-of-2">
            <c-lwc-filter filter={filters.CodigoBarra} input-variant="label-inline"></c-lwc-filter>
            <div class="slds-form-element slds-form-element_horizontal">
                <c-lookup label="Familia" is-lookup=true use-input=true configs={configsFamilia} onremoveselection={removeSelection} data-name="_familiaId"></c-lookup>
            </div>
            <div class="slds-form-element slds-form-element_horizontal">
                <c-lookup label="Marca" is-lookup=true use-input=true configs={configsMarca} onremoveselection={removeSelection} data-name="_marcaId"></c-lookup>
            </div>
            <c-lwc-filter filter={filters.Modelo} input-variant="label-inline"></c-lwc-filter>
        </div>
    </div>
</template>

(the lwcFilter components are lightning-inputs internally)

I got the label to be inline, wrapping my custom lookup lwc inside a div with slds-form-element_horizontal class. But the problem is, as the "input" inside the lookup is not just a normal input, it is wider and as I said before, the spacing between the label and said input is very small.

How can I make them look the same as the base lightning-inputs? And for it to work on every screen size? (because I tried using margin or padding but it doesn't look the same with smaller / bigger screens)

Any help would be appreciated!

joacoiudica
  • 117
  • 1
  • 6

1 Answers1

0

Have you tried to include slds-form-element__control in getContainerClass()? Something like this:

get getContainerClass() {
    let css = 'slds-combobox_container slds-form-element__control'; // slds-has-inline-listbox  // sacado porque moleasta
    // ... rest of logic
    return css;
}

Does it break anything?

David Rubin
  • 196
  • 6