mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-11-28 01:10:58 +01:00
Fixed search bar stealing tab focus
This commit is contained in:
parent
b10e058906
commit
809f943240
File diff suppressed because one or more lines are too long
1
material/assets/javascripts/application.a2b571e1.js
Normal file
1
material/assets/javascripts/application.a2b571e1.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
material/assets/stylesheets/application.cab7c440.css
Normal file
2
material/assets/stylesheets/application.cab7c440.css
Normal file
File diff suppressed because one or more lines are too long
@ -46,7 +46,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block styles %}
|
{% block styles %}
|
||||||
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application.0e9c8aca.css">
|
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application.cab7c440.css">
|
||||||
{% if palette.primary or palette.accent %}
|
{% if palette.primary or palette.accent %}
|
||||||
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-palette.792431c1.css">
|
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-palette.792431c1.css">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -167,7 +167,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="{{ base_url }}/assets/javascripts/application.206c856d.js"></script>
|
<script src="{{ base_url }}/assets/javascripts/application.a2b571e1.js"></script>
|
||||||
{% if lang.t("search.language") != "en" %}
|
{% if lang.t("search.language") != "en" %}
|
||||||
{% set languages = lang.t("search.language").split(",") %}
|
{% set languages = lang.t("search.language").split(",") %}
|
||||||
{% if languages | length and languages[0] != "" %}
|
{% if languages | length and languages[0] != "" %}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
{% import "partials/language.html" as lang with context %}
|
{% import "partials/language.html" as lang with context %}
|
||||||
<div class="md-search" data-md-component="search" role="dialog">
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
<label class="md-search__overlay" for="search"></label>
|
<label class="md-search__overlay" for="search"></label>
|
||||||
<div class="md-search__inner">
|
<div class="md-search__inner" role="search">
|
||||||
<form class="md-search__form" name="search">
|
<form class="md-search__form" name="search">
|
||||||
<input type="text" class="md-search__input" name="query" required placeholder="{{ lang.t('search.placeholder') }}" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
|
<input type="text" class="md-search__input" name="query" required placeholder="{{ lang.t('search.placeholder') }}" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||||
<label class="md-icon md-search__icon" for="search"></label>
|
<label class="md-icon md-search__icon" for="search"></label>
|
||||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset"></button>
|
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||||
|

|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<div class="md-search__output">
|
<div class="md-search__output">
|
||||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||||
|
@ -381,8 +381,8 @@ function initialize(config) { // eslint-disable-line func-style
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Escape: close search */
|
/* Escape or Tab: close search */
|
||||||
} else if (ev.keyCode === 27) {
|
} else if (ev.keyCode === 9 || ev.keyCode === 27) {
|
||||||
toggle.checked = false
|
toggle.checked = false
|
||||||
toggle.dispatchEvent(new CustomEvent("change"))
|
toggle.dispatchEvent(new CustomEvent("change"))
|
||||||
query.blur()
|
query.blur()
|
||||||
@ -392,10 +392,9 @@ function initialize(config) { // eslint-disable-line func-style
|
|||||||
if (query !== document.activeElement)
|
if (query !== document.activeElement)
|
||||||
query.focus()
|
query.focus()
|
||||||
|
|
||||||
/* Vertical arrows and tab: select previous or next search result */
|
/* Vertical arrows: select previous or next search result */
|
||||||
} else if ([9, 38, 40].indexOf(ev.keyCode) !== -1) {
|
} else if ([38, 40].indexOf(ev.keyCode) !== -1) {
|
||||||
const map = ev.shiftKey ? 38 : 40
|
const key = ev.keyCode
|
||||||
const key = ev.keyCode === 9 ? map : ev.keyCode
|
|
||||||
|
|
||||||
/* Retrieve all results */
|
/* Retrieve all results */
|
||||||
const links = Array.prototype.slice.call(
|
const links = Array.prototype.slice.call(
|
||||||
|
@ -276,7 +276,7 @@ export default class Result {
|
|||||||
const article = (
|
const article = (
|
||||||
<li class="md-search-result__item">
|
<li class="md-search-result__item">
|
||||||
<a href={doc.location} title={doc.title}
|
<a href={doc.location} title={doc.title}
|
||||||
class="md-search-result__link">
|
class="md-search-result__link" tabindex="-1">
|
||||||
<article class="md-search-result__article
|
<article class="md-search-result__article
|
||||||
md-search-result__article--document">
|
md-search-result__article--document">
|
||||||
<h1 class="md-search-result__title">
|
<h1 class="md-search-result__title">
|
||||||
@ -297,7 +297,8 @@ export default class Result {
|
|||||||
const section = this.docs_.get(item.ref)
|
const section = this.docs_.get(item.ref)
|
||||||
article.appendChild(
|
article.appendChild(
|
||||||
<a href={section.location} title={section.title}
|
<a href={section.location} title={section.title}
|
||||||
class="md-search-result__link" data-md-rel="anchor">
|
class="md-search-result__link" data-md-rel="anchor"
|
||||||
|
tabindex="-1">
|
||||||
<article class="md-search-result__article">
|
<article class="md-search-result__article">
|
||||||
<h1 class="md-search-result__title">
|
<h1 class="md-search-result__title">
|
||||||
{{ __html: section.title.replace(match, highlight) }}
|
{{ __html: section.title.replace(match, highlight) }}
|
||||||
@ -329,21 +330,27 @@ export default class Result {
|
|||||||
/* Bind click handlers for anchors */
|
/* Bind click handlers for anchors */
|
||||||
const anchors = this.list_.querySelectorAll("[data-md-rel=anchor]")
|
const anchors = this.list_.querySelectorAll("[data-md-rel=anchor]")
|
||||||
Array.prototype.forEach.call(anchors, anchor => {
|
Array.prototype.forEach.call(anchors, anchor => {
|
||||||
anchor.addEventListener("click", ev2 => {
|
["click", "keydown"].forEach(action => {
|
||||||
const toggle = document.querySelector("[data-md-toggle=search]")
|
anchor.addEventListener(action, ev2 => {
|
||||||
if (!(toggle instanceof HTMLInputElement))
|
if (action === "keydown" && ev2.keyCode !== 13)
|
||||||
throw new ReferenceError
|
return
|
||||||
if (toggle.checked) {
|
|
||||||
toggle.checked = false
|
|
||||||
toggle.dispatchEvent(new CustomEvent("change"))
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Hack: prevent default, as the navigation needs to be delayed due
|
/* Close search */
|
||||||
to the search body lock on mobile */
|
const toggle = document.querySelector("[data-md-toggle=search]")
|
||||||
ev2.preventDefault()
|
if (!(toggle instanceof HTMLInputElement))
|
||||||
setTimeout(() => {
|
throw new ReferenceError
|
||||||
document.location.href = anchor.href
|
if (toggle.checked) {
|
||||||
}, 100)
|
toggle.checked = false
|
||||||
|
toggle.dispatchEvent(new CustomEvent("change"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hack: prevent default, as the navigation needs to be delayed due
|
||||||
|
to the search body lock on mobile */
|
||||||
|
ev2.preventDefault()
|
||||||
|
setTimeout(() => {
|
||||||
|
document.location.href = anchor.href
|
||||||
|
}, 100)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -71,12 +71,6 @@ input {
|
|||||||
a {
|
a {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|
||||||
// Remove outline on focused or active links
|
|
||||||
&:active,
|
|
||||||
&:hover {
|
|
||||||
outline-width: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize font-size in all browsers
|
// Normalize font-size in all browsers
|
||||||
@ -125,7 +119,7 @@ th {
|
|||||||
button {
|
button {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border: 0;
|
border: 0;
|
||||||
outline: 0;
|
outline-style: none;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
}
|
}
|
||||||
|
@ -50,20 +50,19 @@
|
|||||||
transition:
|
transition:
|
||||||
color 0.25s,
|
color 0.25s,
|
||||||
opacity 0.25s;
|
opacity 0.25s;
|
||||||
color: $md-color-black--light;
|
color: $md-color-black--lightest;
|
||||||
content: "\E14D"; // content_copy
|
content: "\E14D"; // content_copy
|
||||||
opacity: 0.25;
|
|
||||||
|
|
||||||
// Show on container hover
|
// Show on container hover
|
||||||
pre:hover &,
|
pre:hover &,
|
||||||
.codehilite:hover & {
|
.codehilite:hover & {
|
||||||
opacity: 1;
|
color: $md-color-black--light;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hovered and active icon
|
// Focused or hovered icon
|
||||||
&:hover::before,
|
&:focus::before,
|
||||||
&:active::before {
|
&:hover::before {
|
||||||
color: $md-color-accent;
|
color: $md-color-accent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,15 +25,18 @@
|
|||||||
<!-- Search interface -->
|
<!-- Search interface -->
|
||||||
<div class="md-search" data-md-component="search" role="dialog">
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
<label class="md-search__overlay" for="search"></label>
|
<label class="md-search__overlay" for="search"></label>
|
||||||
<div class="md-search__inner">
|
<div class="md-search__inner" role="search">
|
||||||
<form class="md-search__form" name="search">
|
<form class="md-search__form" name="search">
|
||||||
<input type="text" class="md-search__input" name="query"
|
<input type="text" class="md-search__input" name="query"
|
||||||
required placeholder="{{ lang.t('search.placeholder') }}"
|
required placeholder="{{ lang.t('search.placeholder') }}"
|
||||||
autocapitalize="off" autocorrect="off" autocomplete="off"
|
autocapitalize="off" autocorrect="off" autocomplete="off"
|
||||||
spellcheck="false" data-md-component="query" />
|
spellcheck="false" data-md-component="query"
|
||||||
|
data-md-state="active" />
|
||||||
<label class="md-icon md-search__icon" for="search"></label>
|
<label class="md-icon md-search__icon" for="search"></label>
|
||||||
<button type="reset" class="md-icon md-search__icon"
|
<button type="reset" class="md-icon md-search__icon"
|
||||||
data-md-component="reset"><!-- close --></button>
|
data-md-component="reset" tabindex="-1">
|
||||||
|
<!-- close -->
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<div class="md-search__output">
|
<div class="md-search__output">
|
||||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||||
|
Loading…
Reference in New Issue
Block a user