Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Theme
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Theme
Commits
cbf9622b
Unverified
Commit
cbf9622b
authored
6 months ago
by
Alexis BENOIT
Committed by
GitHub
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Gestion de l'accessibilité pour la recherche (#681)
parent
2c21ce0b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
assets/js/theme/design-system/search.js
+54
-36
54 additions, 36 deletions
assets/js/theme/design-system/search.js
with
54 additions
and
36 deletions
assets/js/theme/design-system/search.js
+
54
−
36
View file @
cbf9622b
/* eslint-disable no-undef */
import
{
focusTrap
}
from
'
../utils/focus-trap
'
;
class
Search
{
constructor
(
button
,
pageFind
)
{
constructor
(
container
)
{
this
.
state
=
{
isOpened
:
false
};
this
.
button
=
button
;
this
.
button
=
document
.
querySelector
(
'
.pagefind-ui__toggle
'
)
;
this
.
element
=
document
.
querySelector
(
'
.search__modal
'
);
this
.
closeButton
=
this
.
element
.
querySelector
(
'
.search__close
'
);
this
.
searchInstance
=
pageFind
;
this
.
searchInstance
=
new
PagefindUI
({
element
:
container
,
showSubResults
:
true
,
processResult
:
()
=>
{
setTimeout
(
this
.
updateAccessibilityMessageRole
.
bind
(
this
),
1500
);
}
});
if
(
!
this
.
element
)
{
return
;
}
this
.
listen
();
this
.
setAccessibility
();
}
setAccessibility
()
{
const
input
=
document
.
querySelector
(
'
.pagefind-ui__search-input
'
);
input
.
setAttribute
(
'
title
'
,
input
.
getAttribute
(
'
placeholder
'
));
// Add element to alert screen reader of the search results
this
.
accessibleMessageContainer
=
document
.
createElement
(
'
div
'
);
this
.
accessibleMessage
=
document
.
createElement
(
'
p
'
);
this
.
accessibleMessageContainer
.
appendChild
(
this
.
accessibleMessage
);
this
.
accessibleMessageContainer
.
setAttribute
(
'
aria-live
'
,
'
polite
'
);
this
.
accessibleMessageContainer
.
setAttribute
(
'
aria-atomic
'
,
'
true
'
);
this
.
accessibleMessageContainer
.
classList
.
add
(
'
sr-only
'
,
'
pagefind-ui__accessible-message
'
);
this
.
element
.
append
(
this
.
accessibleMessageContainer
);
}
listen
()
{
if
(
document
.
body
.
querySelector
(
"
.toc-cta
"
))
{
updateAccessibilityMessageRole
()
{
const
message
=
this
.
element
.
querySelector
(
'
.pagefind-ui__message
'
);
this
.
accessibleMessage
.
innerText
=
message
.
innerText
;
}
listen
()
{
if
(
document
.
body
.
querySelector
(
'
.toc-cta
'
))
{
this
.
button
.
classList
.
add
(
'
in-page-with-toc
'
);
}
this
.
button
.
addEventListener
(
'
click
'
,
()
=>
{
...
...
@@ -39,8 +66,7 @@ class Search {
this
.
toggle
(
false
);
this
.
button
.
focus
();
}
}
else
if
(
event
.
key
===
"
Tab
"
&&
this
.
state
.
isOpened
)
{
}
else
if
(
event
.
key
===
'
Tab
'
&&
this
.
state
.
isOpened
)
{
focusTrap
(
event
,
this
.
element
,
this
.
state
.
isOpened
);
}
this
.
buttonMore
=
this
.
element
.
querySelector
(
'
.pagefind-ui__results + button
'
);
...
...
@@ -52,37 +78,37 @@ class Search {
});
}
clearSearch
()
{
const
button
=
this
.
element
.
querySelector
(
'
.pagefind-ui__button
'
)
;
const
message
=
this
.
element
.
querySelector
(
'
.pagefind-ui__message
'
)
;
const
results
=
this
.
element
.
querySelector
(
'
.pagefind-ui__results
'
)
this
.
input
.
value
=
""
;
clearSearch
()
{
const
button
=
this
.
element
.
querySelector
(
'
.pagefind-ui__button
'
)
,
message
=
this
.
element
.
querySelector
(
'
.pagefind-ui__message
'
)
,
results
=
this
.
element
.
querySelector
(
'
.pagefind-ui__results
'
)
;
this
.
input
.
value
=
''
;
this
.
searchInstance
.
triggerSearch
(
false
);
if
(
message
)
{
message
.
innerText
=
""
;
message
.
innerText
=
''
;
}
if
(
results
)
{
results
.
innerHTML
=
""
;
results
.
innerHTML
=
''
;
}
if
(
button
)
{
button
.
parentElement
.
removeChild
(
button
);
}
}
buttonMoreFocus
()
{
buttonMoreFocus
()
{
const
observer
=
new
MutationObserver
(
mutations
=>
{
mutations
.
forEach
(
mutation
=>
{
mutation
.
addedNodes
.
forEach
(
addedNode
=>
{
if
(
addedNode
instanceof
HTMLAnchorElement
)
{
addedNode
.
focus
();
}
mutation
.
addedNodes
.
forEach
(
addedNode
=>
{
if
(
addedNode
instanceof
HTMLAnchorElement
)
{
addedNode
.
focus
();
}
});
});
});
const
observerConfig
=
{
childList
:
true
,
subtree
:
true
};
observer
.
observe
(
this
.
element
,
observerConfig
);
});
observer
.
observe
(
this
.
element
,
{
childList
:
true
,
subtree
:
true
}
);
}
toggle
(
open
=
!
this
.
state
.
isOpened
)
{
...
...
@@ -101,7 +127,7 @@ class Search {
if
(
el
===
this
.
element
||
this
.
element
.
contains
(
el
)
||
el
.
contains
(
this
.
element
))
{
return
;
}
el
.
setAttribute
(
'
inert
'
,
''
);
this
.
inertElements
.
push
(
el
);
});
...
...
@@ -120,19 +146,11 @@ class Search {
// Selectors
window
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
const
pageFind
Search
=
document
.
querySelector
(
"
#search
"
);
const
pageFind
Container
=
document
.
querySelector
(
'
#search
'
);
if
(
typeof
PagefindUI
==
"
undefined
"
)
return
;
if
(
typeof
PagefindUI
==
=
'
undefined
'
)
return
;
if
(
pageFindSearch
)
{
let
pageFind
=
new
PagefindUI
({
element
:
pageFindSearch
,
showSubResults
:
true
});
(
function
()
{
const
searchButton
=
document
.
querySelector
(
"
.pagefind-ui__toggle
"
);
new
Search
(
searchButton
,
pageFind
);
})();
if
(
pageFindContainer
)
{
new
Search
(
pageFindContainer
);
}
});
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