svelte with tailwind showing different output in Firefox and Chrome

Viewed 68

I was designing a Tags input field much like StackOverflow. I designed it using Sveltekit and Tailwindcss . But it was showing different outputs in Firefox and Chrome. I searched through the code using debugger tools. As a result, I was unable to find any solution.

I designed this :

enter image description here

Code of this :

<script lang="ts">
     let TagObj: { Input: string; Focus: boolean; List: string[]; Suggested: string[] } = {
        Input: '' as string,
        Focus: false as boolean,
        List: [] as string[],
        Suggested: [] as string[]
    };
    / TAGS
    function onKeyPressTags(e: { keyCode: any }) {
        switch (e.keyCode) {
            case 32:
                onKeyTag();
                break;
            case 13:
                onKeyTag();
                break;
        }
    }
    function onKeyTag() {
        if (TagObj.Input.trim() != ("" as String)) {
            TagObj.List = [...TagObj.List, TagObj.Input.trim()];
            TagObj.Input = '' as string;
        }
    }

</script>

<div class="mx-4 mt-3 h-fit w-[95%] rounded-lg border-2 border-[#24262b] bg-[#303338] p-2 text-lg font-medium text-[#98999e]  outline-0   {TagObj.Focus ? 'border-sky-500' : ''}  ">
    <ul class="flex flex-row flex-wrap gap-2">
        {#each TagObj.List as t}
        <li class="m-1 rounded-md bg-[#3d4951] px-2 py-1 text-[#9bc0da] hover:cursor-pointer hover:bg-slate-600 hover:text-teal-200">
            {t}
        </li>
        {/each}
        <input on:keypress={onKeyPressTags} maxlength=20 bind:value={TagObj.Input} on:focus={() => { TagObj.Focus = true;}} on:blur={() => { TagObj.Focus = false; }} type="text" class=" inline w-fit grow bg-inherit  border-0  outline-0  " />
    </ul>
</div>

This is how chrome is showing : enter image description here

This is how Firefox is showing : enter image description here

A small blue border is showing around the input field in Firefox. I couldn't find the reason behind it. How i show the exact same UI in Firefox ?

1 Answers

It seems to be the focus:outline behavior that's different in Firefox than chrome.

See this REPL

Adding focus:outline-none to the input gets rid of it.

<input maxlength=20 type="text" class=" inline w-fit grow bg-inherit  border-0  outline-0 focus:outline-none" />

Sidenote: outlines are relevant pieces of functionality useful for a11y and keyboard users. So it is generally recommended to keep some form of physical indication when an input has focus and is active.

Related