Skip to content

Commit

Permalink
Search spellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jan 28, 2021
1 parent 0a12284 commit 6301056
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ import {html} from "htl";
import {arrayify} from "./array.js";
import {preventDefault} from "./event.js";
import {formatNumber, stringify} from "./format.js";
import {boxSizing, defaultStyle, mr1, mr2} from "./style.js";
import {boxSizing, defaultStyle, mr1, mr2, textStyle} from "./style.js";

export function Search(data, {
format = value => formatNumber(value.length), // length format
label = "results",
value = "", // initial search query
placeholder = "Search", // placeholder text to show when empty
columns = data.columns,
spellcheck,
filter = columns === undefined ? searchFilter : columnFilter(columns), // returns the filter function given query
style = {}
} = {}) {
data = arrayify(data);
label = html`<span>${label}`;
const {width = "180px", ...formStyle} = style;
const form = html`<form style=${{...defaultStyle, ...formStyle}} onsubmit=${preventDefault}>
<input name=input type=search style=${{...mr2, ...boxSizing, width}} placeholder=${placeholder} value=${value} oninput=${oninput}><output name=output style=${mr1}></output>${label}
<input name=input type=search spellcheck=${spellcheck === undefined ? false : spellcheck + ""} style=${{...mr2, ...textStyle, ...boxSizing, width}} placeholder=${placeholder} value=${value} oninput=${oninput}><output name=output style=${mr1}></output>${label}
</form>`;
const {input, output} = form.elements;
function oninput() {
Expand Down
1 change: 1 addition & 0 deletions test/inputs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
searchLabelHtml,
searchLabelValue,
searchPlaceholder,
searchSpellcheck,
searchStyle,
searchValue,
searchWide
Expand Down
4 changes: 4 additions & 0 deletions test/inputs/searches.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export async function searchPlaceholder() {
return Search(["red", "green", "blue"], {placeholder: "dollars&pounds"});
}

export async function searchSpellcheck() {
return Search(["red", "green", "blue"], {spellcheck: false});
}

export async function searchStyle() {
return Search(["red", "green", "blue"], {style: {background: "red"}});
}
Expand Down
3 changes: 3 additions & 0 deletions test/output/searchSpellcheck.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<form style="display: flex; align-items: center; min-height: 33px; font: var(--sans-serif) 13px 13px;">
<input name="input" type="search" spellcheck="false" placeholder="Search" value="" style="margin-right: 0.5em; box-sizing: border-box; width: 180px;"><output name="output" style="margin-right: 0.25em;"></output><span style="display: none;">results</span>
</form>

0 comments on commit 6301056

Please sign in to comment.