How to highlight searched text in solid
I have this code: https://github.com/nikitavoloboev/kuskus
GitHub
GitHub - nikitavoloboev/kuskus: Fast todo app
Fast todo app. Contribute to nikitavoloboev/kuskus development by creating an account on GitHub.
25 Replies
if you clone repo and press
f
key and try do a search
it should do a highlight of matched todos as in the image above
the thing is that I am not sure how to go about doing thisGitHub
kuskus/LocalSearch.tsx at main · nikitavoloboev/kuskus
Fast todo app. Contribute to nikitavoloboev/kuskus development by creating an account on GitHub.
is the search component
I checked and the usual way to do this, for example discord does this
somehow add spans inside the jsx
GitHub
kuskus/Todo.tsx at main · nikitavoloboev/kuskus
Fast todo app. Contribute to nikitavoloboev/kuskus development by creating an account on GitHub.
in here is where in my case the
todo
gets renderedI thought of doing something like this
but that does not do what I thought it'd do as its a string
mark.js example with pure JavaScript - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
I found this library too that does what I want but not sure how it would be integrated with solid
as that does raw dom access
if anyone can help out, I would be forever grateful ❤️
we are using something like this in the solid-primitives site: https://github.com/solidjs-community/solid-primitives/blob/main/site/src/components/Search/Search.tsx#L114
GitHub
solid-primitives/Search.tsx at main · solidjs-community/solid-primi...
A library of high-quality primitives that extend SolidJS reactivity. - solid-primitives/Search.tsx at main · solidjs-community/solid-primitives
oh beauty
will try now
btw on the same site I still get issue with solid-primitives-autofocus
no idea whats up with it
I do things as per the docs
on 2nd time it all the time doesn't focus on the input
yeah I know
but to debug it I have to clone your repo
so I just haven't got around to it yet 😛
if you get a chance, would be grateful ❤️
will try fix search now
I made the repo easily cloneable
just
pnpm i
and pnpm dev
all state is in signals
requestAnimationFrame
hopefully something like codeflow would work
is so fancy
first time I see this
@thetarnav solid-primitives code is quite hard to understand
do you know if perhaps this can work somehow
I googled
string to dom jsx
but results are for react thereStack Overflow
How do you get an HTML string from JSX without React. I'm using Sol...
I'm not using React, so this won't work
ReactDomServer.renderToString(<div>p</div>)
I'm currently rendering the jsx in a hidden div with an id on the browser and then using
document.
I think you could
but not this way
import { renderToString } from "solid-js/web"
tried this too
or wait
there has to be some other method
that is string to DOM
ok this works
will adapt it to work with multiple matches
yup, something like that is what I would do
Maybe this is worth adding to solid-primitives
Recreating n spans on each keypress can be avoided
This would work with
<span innerHTML={turnHighlightsIntoSpans(str, match)}/>
. But if you go this route, please escape string
in case it already contains HTML. Also you need to escape match
in case it has regex notation in it.here's an initial draft:
https://github.com/solidjs-community/solid-primitives/blob/site-highlights/site/src/primitives/highlight.ts#L7
GitHub
solid-primitives/highlight.ts at site-highlights · solidjs-communit...
A library of high-quality primitives that extend SolidJS reactivity. - solid-primitives/highlight.ts at site-highlights · solidjs-community/solid-primitives