Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rescheduled 🗓️
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3lingo
rescheduled 🗓️
Commits
fb6464b7
Unverified
Commit
fb6464b7
authored
4 months ago
by
Felix Eckhofer
Browse files
Options
Downloads
Patches
Plain Diff
Debounce filter so it feels snappier
parent
a7ad602e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/javascript/controllers/filteredlist_controller.js
+13
-5
13 additions, 5 deletions
app/javascript/controllers/filteredlist_controller.js
with
13 additions
and
5 deletions
app/javascript/controllers/filteredlist_controller.js
+
13
−
5
View file @
fb6464b7
import
{
Controller
}
from
"
@hotwired/stimulus
"
;
import
{
Controller
}
from
"
@hotwired/stimulus
"
;
function
debounce
(
func
,
wait
)
{
let
timeout
;
return
function
(...
args
)
{
clearTimeout
(
timeout
);
timeout
=
setTimeout
(()
=>
func
.
apply
(
this
,
args
),
wait
);
};
}
export
default
class
extends
Controller
{
export
default
class
extends
Controller
{
static
targets
=
[
"
input
"
,
"
list
"
];
static
targets
=
[
"
input
"
,
"
list
"
];
connect
()
{
connect
()
{
//
this.
options = Array.from(this.listTarget.children)
this
.
filter
=
debounce
(
this
.
filter_nodebounce
.
bind
(
this
),
300
);
}
}
filter
()
{
filter
_nodebounce
()
{
const
query
=
this
.
inputTarget
.
value
.
toLowerCase
()
const
query
=
this
.
inputTarget
.
value
.
toLowerCase
()
;
// Filter options by the `data-filteredlist-match` attribute
// Filter options by the `data-filteredlist-match` attribute
for
(
const
option
of
this
.
listTarget
.
children
)
{
for
(
const
option
of
this
.
listTarget
.
children
)
{
if
(
option
.
dataset
.
filteredlistMatch
.
includes
(
query
))
{
if
(
option
.
dataset
.
filteredlistMatch
.
includes
(
query
))
{
option
.
classList
.
remove
(
"
hidden
"
)
option
.
classList
.
remove
(
"
hidden
"
)
;
}
else
{
}
else
{
option
.
classList
.
add
(
"
hidden
"
)
option
.
classList
.
add
(
"
hidden
"
)
;
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment