livewire-datatables icon indicating copy to clipboard operation
livewire-datatables copied to clipboard

Search issue with Callback method when the return value consists HTML element.

Open NikarashiHatsu opened this issue 4 years ago • 0 comments

I stumbled upon this bug, accidentally, and I'm not having enough time to check the code to submit a pull request.

How to reproduce

First, define the column

public function columns()
{
    return [
        Column::callback(['role'], function($role) {
            switch ($role) {
                case "super_admin":
                    return "<span class='px-1 bg-red-500 text-white rounded text-xs'>Super Admin</span>";
                    break;
                case "admin_irwasum":
                    return "<span class='px-1 bg-green-500 text-white rounded text-xs'>Admin Irwasum</span>";
                    break;
                ... // more roles below
            }
        })
        ->label('Tipe Akun')
        ->searchable(),
    ];
}

Second, search the data using one character

Screenshot_20220104_165815

Third, see the result

Screenshot_20220104_165906

Additional notes

  • This bug occurs only when one character is searched, if the query is more than 2 characters, the bug won't occur.
  • I modified the cell column, only to add DaisyUI's dark mode classes. text-base-content, so I'm pretty sure it won't affect.

Personal thoughts

I think this bug is regex-related? Because if I see the code using Chrome's inspect element feature, here's what I got: Screenshot_20220104_170252

How I expect the feature should be

Screenshot_20220104_170650 The HTML element is left unchanged, only the text inside or the content is changed.

NikarashiHatsu avatar Jan 04 '22 10:01 NikarashiHatsu