Added reset button for search

This commit is contained in:
squidfunk 2017-03-19 19:49:19 +01:00 committed by Martin Donath
parent da02320bb5
commit a2ff177885
9 changed files with 57 additions and 24 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -38,7 +38,7 @@
<script src="{{ base_url }}/assets/javascripts/modernizr-56ade86843.js"></script> <script src="{{ base_url }}/assets/javascripts/modernizr-56ade86843.js"></script>
{% endblock %} {% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-76741b64bc.css"> <link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-d6bceb5018.css">
{% if config.extra.palette %} {% if config.extra.palette %}
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-66fa0d9bba.palette.css"> <link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-66fa0d9bba.palette.css">
{% endif %} {% endif %}
@ -151,7 +151,7 @@
{% endblock %} {% endblock %}
</div> </div>
{% block scripts %} {% block scripts %}
<script src="{{ base_url }}/assets/javascripts/application-3964c0cb56.js"></script> <script src="{{ base_url }}/assets/javascripts/application-0f66d83d23.js"></script>
<script>app.initialize({url:{base:"{{ base_url }}"}})</script> <script>app.initialize({url:{base:"{{ base_url }}"}})</script>
{% for path in extra_javascript %} {% for path in extra_javascript %}
<script src="{{ path }}"></script> <script src="{{ path }}"></script>

View File

@ -3,8 +3,9 @@
<div class="md-search__overlay"></div> <div class="md-search__overlay"></div>
<div class="md-search__inner"> <div class="md-search__inner">
<form class="md-search__form" name="search"> <form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" placeholder="{{ lang.t('search.placeholder') }}" accesskey="s" 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') }}" accesskey="s" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<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">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>

View File

@ -141,7 +141,7 @@ function initialize(config) { // eslint-disable-line func-style
/* Component: search results */ /* Component: search results */
new Material.Event.Listener("[data-md-component=query]", [ new Material.Event.Listener("[data-md-component=query]", [
"focus", "keyup" "focus", "keyup", "change"
], new Material.Search.Result("[data-md-component=result]", () => { ], new Material.Search.Result("[data-md-component=result]", () => {
return fetch(`${config.url.base}/mkdocs/search_index.json`, { return fetch(`${config.url.base}/mkdocs/search_index.json`, {
credentials: "same-origin" credentials: "same-origin"

View File

@ -159,12 +159,12 @@
// Search input // Search input
&__input { &__input {
position: relative; position: relative;
padding: 0 1.6rem 0 7.2rem; padding: 0 4.8rem 0 7.2rem;
text-overflow: ellipsis; text-overflow: ellipsis;
z-index: 1; z-index: 1;
// Placeholder and icon color in active state // Placeholder and icon color in active state
+ .md-search__icon, ~ .md-search__icon,
&::placeholder { &::placeholder {
color: $md-color-black--light; color: $md-color-black--light;
} }
@ -225,13 +225,16 @@
// Icons // Icons
&__icon { &__icon {
position: absolute; position: absolute;
top: $md-icon-padding;
left: $md-icon-padding + $md-icon-margin;
transition: color 0.25s; transition: color 0.25s;
font-size: $md-icon-size; font-size: $md-icon-size;
cursor: pointer; cursor: pointer;
z-index: 1; z-index: 1;
// Search icon
&[for="search"] {
top: $md-icon-padding;
left: $md-icon-padding + $md-icon-margin;
// Set search icon on pseudo class, so it can be overridden for mobile // Set search icon on pseudo class, so it can be overridden for mobile
// and tablet when the search is rendered in an overlay // and tablet when the search is rendered in an overlay
&::before { &::before {
@ -244,12 +247,40 @@
left: 1.6rem; left: 1.6rem;
// Show back arrow instead of search icon // Show back arrow instead of search icon
&::before { &[for="search"]::before {
content: "arrow_back"; content: "arrow_back";
} }
} }
} }
// Reset button
&[type="reset"] {
top: $md-icon-padding;
right: $md-icon-padding + $md-icon-margin;
transform: scale(0.25);
transition:
transform 0.25s,
opacity 0.25s;
opacity: 0;
// [tablet portrait -]: Full-screen search bar
@include break-to-device(tablet portrait) {
top: 1.6rem;
right: 1.6rem;
}
// Non-empty input field ...
.md-search__input:valid ~ & {
// ...and expanded overlay
[data-md-toggle="search"]:checked ~ .md-header & {
transform: scale(1);
opacity: 1;
}
}
}
}
// Search output container // Search output container
&__output { &__output {
position: absolute; position: absolute;

View File

@ -28,10 +28,11 @@
<div class="md-search__inner"> <div class="md-search__inner">
<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"
placeholder="{{ lang.t('search.placeholder') }}" required placeholder="{{ lang.t('search.placeholder') }}"
accesskey="s" autocapitalize="off" autocorrect="off" accesskey="s" autocapitalize="off" autocorrect="off"
autocomplete="off" spellcheck="false" data-md-component="query" /> autocomplete="off" spellcheck="false" data-md-component="query" />
<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">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>