@spectrum-web-components/search 0.42.5 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/custom-elements.json +16 -0
- package/package.json +7 -7
- package/src/Search.d.ts +1 -0
- package/src/Search.dev.js +9 -1
- package/src/Search.dev.js.map +2 -2
- package/src/Search.js +3 -3
- package/src/Search.js.map +2 -2
- package/stories/search.stories.js +3 -0
- package/stories/search.stories.js.map +2 -2
- package/test/search.test.js +69 -57
- package/test/search.test.js.map +2 -2
package/README.md
CHANGED
|
@@ -77,3 +77,12 @@ import { Search } from '@spectrum-web-components/search';
|
|
|
77
77
|
## Events
|
|
78
78
|
|
|
79
79
|
The `submit` event fires when the `<sp-search>` is submitted. This is a non-`composed` event inline with what you would expect a [`<form />`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit_event){:target="\_blank"} to fire. If you choose to prevent the default of this event, the default action for the underlying `<form />` element will also be prevented, which will allow you to handle the search action in javascript.
|
|
80
|
+
|
|
81
|
+
## Properties
|
|
82
|
+
|
|
83
|
+
### holdValueOnEscape
|
|
84
|
+
|
|
85
|
+
- Type: `boolean`
|
|
86
|
+
- Default: `false`
|
|
87
|
+
|
|
88
|
+
If `holdValueOnEscape` controls whether the typed value should be held (i.e., not cleared or reset) when the Escape key is pressed. If set to true, pressing the Escape key will not affect the value in the search field.
|
package/custom-elements.json
CHANGED
|
@@ -75,6 +75,15 @@
|
|
|
75
75
|
"default": "'Search'",
|
|
76
76
|
"attribute": "placeholder"
|
|
77
77
|
},
|
|
78
|
+
{
|
|
79
|
+
"kind": "field",
|
|
80
|
+
"name": "holdValueOnEscape",
|
|
81
|
+
"type": {
|
|
82
|
+
"text": "boolean"
|
|
83
|
+
},
|
|
84
|
+
"privacy": "public",
|
|
85
|
+
"attribute": "holdValueOnEscape"
|
|
86
|
+
},
|
|
78
87
|
{
|
|
79
88
|
"kind": "field",
|
|
80
89
|
"name": "form",
|
|
@@ -180,6 +189,13 @@
|
|
|
180
189
|
},
|
|
181
190
|
"default": "'Search'",
|
|
182
191
|
"fieldName": "placeholder"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"name": "holdValueOnEscape",
|
|
195
|
+
"type": {
|
|
196
|
+
"text": "boolean"
|
|
197
|
+
},
|
|
198
|
+
"fieldName": "holdValueOnEscape"
|
|
183
199
|
}
|
|
184
200
|
],
|
|
185
201
|
"superclass": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/search",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"lit-html"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@spectrum-web-components/base": "^0.
|
|
61
|
-
"@spectrum-web-components/button": "^0.
|
|
62
|
-
"@spectrum-web-components/icon": "^0.
|
|
63
|
-
"@spectrum-web-components/icons-workflow": "^0.
|
|
64
|
-
"@spectrum-web-components/textfield": "^0.
|
|
60
|
+
"@spectrum-web-components/base": "^0.44.0",
|
|
61
|
+
"@spectrum-web-components/button": "^0.44.0",
|
|
62
|
+
"@spectrum-web-components/icon": "^0.44.0",
|
|
63
|
+
"@spectrum-web-components/icons-workflow": "^0.44.0",
|
|
64
|
+
"@spectrum-web-components/textfield": "^0.44.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@spectrum-css/search": "^7.1.0"
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"./sp-*.js",
|
|
73
73
|
"./**/*.dev.js"
|
|
74
74
|
],
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "0002d42ce82463b85022e5aa5f7aba8484cba096"
|
|
76
76
|
}
|
package/src/Search.d.ts
CHANGED
package/src/Search.dev.js
CHANGED
|
@@ -46,6 +46,9 @@ export class Search extends Textfield {
|
|
|
46
46
|
}
|
|
47
47
|
handleKeydown(event) {
|
|
48
48
|
const { code } = event;
|
|
49
|
+
if (code === "Escape" && this.holdValueOnEscape) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
49
52
|
if (!this.value || code !== "Escape") {
|
|
50
53
|
return;
|
|
51
54
|
}
|
|
@@ -95,7 +98,9 @@ export class Search extends Textfield {
|
|
|
95
98
|
}
|
|
96
99
|
firstUpdated(changedProperties) {
|
|
97
100
|
super.firstUpdated(changedProperties);
|
|
98
|
-
this.
|
|
101
|
+
if (!this.hasAttribute("holdValueOnEscape")) {
|
|
102
|
+
this.inputElement.setAttribute("type", "search");
|
|
103
|
+
}
|
|
99
104
|
}
|
|
100
105
|
willUpdate() {
|
|
101
106
|
this.multiline = false;
|
|
@@ -113,6 +118,9 @@ __decorateClass([
|
|
|
113
118
|
__decorateClass([
|
|
114
119
|
property()
|
|
115
120
|
], Search.prototype, "placeholder", 2);
|
|
121
|
+
__decorateClass([
|
|
122
|
+
property({ type: Boolean })
|
|
123
|
+
], Search.prototype, "holdValueOnEscape", 2);
|
|
116
124
|
__decorateClass([
|
|
117
125
|
query("#form")
|
|
118
126
|
], Search.prototype, "form", 2);
|
package/src/Search.dev.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["Search.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n nothing,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport { Textfield } from '@spectrum-web-components/textfield';\nimport '@spectrum-web-components/button/sp-clear-button.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js';\n\nimport searchStyles from './search.css.js';\n\nconst stopPropagation = (event: Event): void => event.stopPropagation();\n\n/**\n * @element sp-search\n * @slot help-text - default or non-negative help text to associate to your form element\n * @slot negative-help-text - negative help text to associate to your form element when `invalid`\n *\n * @fires submit - The search form has been submitted.\n */\nexport class Search extends Textfield {\n public static override get styles(): CSSResultArray {\n return [...super.styles, searchStyles];\n }\n\n @property()\n public action = '';\n\n @property()\n public override label = 'Search';\n\n @property()\n public method?: 'get' | 'post' | 'dialog';\n\n @property()\n public override placeholder = 'Search';\n\n @query('#form')\n public form!: HTMLFormElement;\n\n private handleSubmit(event: Event): void {\n const applyDefault = this.dispatchEvent(\n new Event('submit', {\n cancelable: true,\n bubbles: true,\n })\n );\n if (!applyDefault) {\n event.preventDefault();\n }\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n if (!this.value || code !== 'Escape') {\n return;\n }\n this.reset();\n }\n\n public async reset(): Promise<void> {\n this.value = '';\n await this.updateComplete;\n this.focusElement.dispatchEvent(\n new InputEvent('input', {\n bubbles: true,\n composed: true,\n })\n );\n // The native `change` event on an `input` element is not composed,\n // so this synthetic replication of a `change` event must not be\n // either as the `Textfield` baseclass should only need to handle\n // the native variant of this interaction.\n this.focusElement.dispatchEvent(\n new InputEvent('change', {\n bubbles: true,\n })\n );\n }\n\n protected override renderField(): TemplateResult {\n return html`\n <form\n action=${this.action}\n id=\"form\"\n method=${ifDefined(this.method)}\n @submit=${this.handleSubmit}\n @reset=${this.reset}\n @keydown=${this.handleKeydown}\n >\n <sp-icon-magnify\n class=\"icon magnifier icon-workflow icon-search\"\n ></sp-icon-magnify>\n ${super.renderField()}\n ${this.value\n ? html`\n <sp-clear-button\n id=\"button\"\n label=\"Reset\"\n tabindex=\"-1\"\n type=\"reset\"\n size=${ifDefined(this.size)}\n @keydown=${stopPropagation}\n ></sp-clear-button>\n `\n : nothing}\n </form>\n `;\n }\n\n public override firstUpdated(changedProperties: PropertyValues): void {\n super.firstUpdated(changedProperties);\n this.inputElement.setAttribute('type', 'search');\n }\n\n public override willUpdate(): void {\n this.multiline = false;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EACA;AAAA,OAGG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,iBAAiB;AAE1B,SAAS,iBAAiB;AAC1B,OAAO;AACP,OAAO;AAEP,OAAO,kBAAkB;AAEzB,MAAM,kBAAkB,CAAC,UAAuB,MAAM,gBAAgB;AAS/D,aAAM,eAAe,UAAU;AAAA,EAA/B;AAAA;AAMH,SAAO,SAAS;AAGhB,SAAgB,QAAQ;AAMxB,SAAgB,cAAc;AAAA;AAAA,EAd9B,WAA2B,SAAyB;AAChD,WAAO,CAAC,GAAG,MAAM,QAAQ,YAAY;AAAA,EACzC;AAAA,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n nothing,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport { Textfield } from '@spectrum-web-components/textfield';\nimport '@spectrum-web-components/button/sp-clear-button.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js';\n\nimport searchStyles from './search.css.js';\n\nconst stopPropagation = (event: Event): void => event.stopPropagation();\n\n/**\n * @element sp-search\n * @slot help-text - default or non-negative help text to associate to your form element\n * @slot negative-help-text - negative help text to associate to your form element when `invalid`\n *\n * @fires submit - The search form has been submitted.\n */\nexport class Search extends Textfield {\n public static override get styles(): CSSResultArray {\n return [...super.styles, searchStyles];\n }\n\n @property()\n public action = '';\n\n @property()\n public override label = 'Search';\n\n @property()\n public method?: 'get' | 'post' | 'dialog';\n\n @property()\n public override placeholder = 'Search';\n\n @property({ type: Boolean })\n public holdValueOnEscape!: boolean;\n\n @query('#form')\n public form!: HTMLFormElement;\n\n private handleSubmit(event: Event): void {\n const applyDefault = this.dispatchEvent(\n new Event('submit', {\n cancelable: true,\n bubbles: true,\n })\n );\n if (!applyDefault) {\n event.preventDefault();\n }\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n if (code === 'Escape' && this.holdValueOnEscape) {\n return;\n }\n if (!this.value || code !== 'Escape') {\n return;\n }\n this.reset();\n }\n\n public async reset(): Promise<void> {\n this.value = '';\n await this.updateComplete;\n this.focusElement.dispatchEvent(\n new InputEvent('input', {\n bubbles: true,\n composed: true,\n })\n );\n // The native `change` event on an `input` element is not composed,\n // so this synthetic replication of a `change` event must not be\n // either as the `Textfield` baseclass should only need to handle\n // the native variant of this interaction.\n this.focusElement.dispatchEvent(\n new InputEvent('change', {\n bubbles: true,\n })\n );\n }\n\n protected override renderField(): TemplateResult {\n return html`\n <form\n action=${this.action}\n id=\"form\"\n method=${ifDefined(this.method)}\n @submit=${this.handleSubmit}\n @reset=${this.reset}\n @keydown=${this.handleKeydown}\n >\n <sp-icon-magnify\n class=\"icon magnifier icon-workflow icon-search\"\n ></sp-icon-magnify>\n ${super.renderField()}\n ${this.value\n ? html`\n <sp-clear-button\n id=\"button\"\n label=\"Reset\"\n tabindex=\"-1\"\n type=\"reset\"\n size=${ifDefined(this.size)}\n @keydown=${stopPropagation}\n ></sp-clear-button>\n `\n : nothing}\n </form>\n `;\n }\n\n public override firstUpdated(changedProperties: PropertyValues): void {\n super.firstUpdated(changedProperties);\n // if holdValueOnEscape is not set, default to search type\n if (!this.hasAttribute('holdValueOnEscape')) {\n this.inputElement.setAttribute('type', 'search');\n }\n }\n\n public override willUpdate(): void {\n this.multiline = false;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EACA;AAAA,OAGG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,iBAAiB;AAE1B,SAAS,iBAAiB;AAC1B,OAAO;AACP,OAAO;AAEP,OAAO,kBAAkB;AAEzB,MAAM,kBAAkB,CAAC,UAAuB,MAAM,gBAAgB;AAS/D,aAAM,eAAe,UAAU;AAAA,EAA/B;AAAA;AAMH,SAAO,SAAS;AAGhB,SAAgB,QAAQ;AAMxB,SAAgB,cAAc;AAAA;AAAA,EAd9B,WAA2B,SAAyB;AAChD,WAAO,CAAC,GAAG,MAAM,QAAQ,YAAY;AAAA,EACzC;AAAA,EAoBQ,aAAa,OAAoB;AACrC,UAAM,eAAe,KAAK;AAAA,MACtB,IAAI,MAAM,UAAU;AAAA,QAChB,YAAY;AAAA,QACZ,SAAS;AAAA,MACb,CAAC;AAAA,IACL;AACA,QAAI,CAAC,cAAc;AACf,YAAM,eAAe;AAAA,IACzB;AAAA,EACJ;AAAA,EAEQ,cAAc,OAA4B;AAC9C,UAAM,EAAE,KAAK,IAAI;AACjB,QAAI,SAAS,YAAY,KAAK,mBAAmB;AAC7C;AAAA,IACJ;AACA,QAAI,CAAC,KAAK,SAAS,SAAS,UAAU;AAClC;AAAA,IACJ;AACA,SAAK,MAAM;AAAA,EACf;AAAA,EAEA,MAAa,QAAuB;AAChC,SAAK,QAAQ;AACb,UA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ty;var c=Object.getOwnPropertyDescriptor;var r=(o,s,e,t)=>{for(var i=t>1?void 0:t?c(s,e):s,n=o.length-1,
|
|
1
|
+
"use strict";var d=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var r=(o,s,e,t)=>{for(var i=t>1?void 0:t?c(s,e):s,n=o.length-1,a;n>=0;n--)(a=o[n])&&(i=(t?a(s,e,i):a(i))||i);return t&&i&&d(s,e,i),i};import{html as p,nothing as m}from"@spectrum-web-components/base";import{property as l,query as h}from"@spectrum-web-components/base/src/decorators.js";import{ifDefined as u}from"@spectrum-web-components/base/src/directives.js";import{Textfield as b}from"@spectrum-web-components/textfield";import"@spectrum-web-components/button/sp-clear-button.js";import"@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js";import f from"./search.css.js";const v=o=>o.stopPropagation();export class Search extends b{constructor(){super(...arguments);this.action="";this.label="Search";this.placeholder="Search"}static get styles(){return[...super.styles,f]}handleSubmit(e){this.dispatchEvent(new Event("submit",{cancelable:!0,bubbles:!0}))||e.preventDefault()}handleKeydown(e){const{code:t}=e;t==="Escape"&&this.holdValueOnEscape||!this.value||t!=="Escape"||this.reset()}async reset(){this.value="",await this.updateComplete,this.focusElement.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0})),this.focusElement.dispatchEvent(new InputEvent("change",{bubbles:!0}))}renderField(){return p`
|
|
2
2
|
<form
|
|
3
3
|
action=${this.action}
|
|
4
4
|
id="form"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
class="icon magnifier icon-workflow icon-search"
|
|
12
12
|
></sp-icon-magnify>
|
|
13
13
|
${super.renderField()}
|
|
14
|
-
${this.value?
|
|
14
|
+
${this.value?p`
|
|
15
15
|
<sp-clear-button
|
|
16
16
|
id="button"
|
|
17
17
|
label="Reset"
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
></sp-clear-button>
|
|
23
23
|
`:m}
|
|
24
24
|
</form>
|
|
25
|
-
`}firstUpdated(e){super.firstUpdated(e),this.inputElement.setAttribute("type","search")}willUpdate(){this.multiline=!1}}r([l()],Search.prototype,"action",2),r([l()],Search.prototype,"label",2),r([l()],Search.prototype,"method",2),r([l()],Search.prototype,"placeholder",2),r([
|
|
25
|
+
`}firstUpdated(e){super.firstUpdated(e),this.hasAttribute("holdValueOnEscape")||this.inputElement.setAttribute("type","search")}willUpdate(){this.multiline=!1}}r([l()],Search.prototype,"action",2),r([l()],Search.prototype,"label",2),r([l()],Search.prototype,"method",2),r([l()],Search.prototype,"placeholder",2),r([l({type:Boolean})],Search.prototype,"holdValueOnEscape",2),r([h("#form")],Search.prototype,"form",2);
|
|
26
26
|
//# sourceMappingURL=Search.js.map
|
package/src/Search.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["Search.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n nothing,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport { Textfield } from '@spectrum-web-components/textfield';\nimport '@spectrum-web-components/button/sp-clear-button.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js';\n\nimport searchStyles from './search.css.js';\n\nconst stopPropagation = (event: Event): void => event.stopPropagation();\n\n/**\n * @element sp-search\n * @slot help-text - default or non-negative help text to associate to your form element\n * @slot negative-help-text - negative help text to associate to your form element when `invalid`\n *\n * @fires submit - The search form has been submitted.\n */\nexport class Search extends Textfield {\n public static override get styles(): CSSResultArray {\n return [...super.styles, searchStyles];\n }\n\n @property()\n public action = '';\n\n @property()\n public override label = 'Search';\n\n @property()\n public method?: 'get' | 'post' | 'dialog';\n\n @property()\n public override placeholder = 'Search';\n\n @query('#form')\n public form!: HTMLFormElement;\n\n private handleSubmit(event: Event): void {\n const applyDefault = this.dispatchEvent(\n new Event('submit', {\n cancelable: true,\n bubbles: true,\n })\n );\n if (!applyDefault) {\n event.preventDefault();\n }\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n if (!this.value || code !== 'Escape') {\n return;\n }\n this.reset();\n }\n\n public async reset(): Promise<void> {\n this.value = '';\n await this.updateComplete;\n this.focusElement.dispatchEvent(\n new InputEvent('input', {\n bubbles: true,\n composed: true,\n })\n );\n // The native `change` event on an `input` element is not composed,\n // so this synthetic replication of a `change` event must not be\n // either as the `Textfield` baseclass should only need to handle\n // the native variant of this interaction.\n this.focusElement.dispatchEvent(\n new InputEvent('change', {\n bubbles: true,\n })\n );\n }\n\n protected override renderField(): TemplateResult {\n return html`\n <form\n action=${this.action}\n id=\"form\"\n method=${ifDefined(this.method)}\n @submit=${this.handleSubmit}\n @reset=${this.reset}\n @keydown=${this.handleKeydown}\n >\n <sp-icon-magnify\n class=\"icon magnifier icon-workflow icon-search\"\n ></sp-icon-magnify>\n ${super.renderField()}\n ${this.value\n ? html`\n <sp-clear-button\n id=\"button\"\n label=\"Reset\"\n tabindex=\"-1\"\n type=\"reset\"\n size=${ifDefined(this.size)}\n @keydown=${stopPropagation}\n ></sp-clear-button>\n `\n : nothing}\n </form>\n `;\n }\n\n public override firstUpdated(changedProperties: PropertyValues): void {\n super.firstUpdated(changedProperties);\n this.inputElement.setAttribute('type', 'search');\n }\n\n public override willUpdate(): void {\n this.multiline = false;\n }\n}\n"],
|
|
5
|
-
"mappings": "qNAYA,OAEI,QAAAA,EACA,WAAAC,MAGG,gCACP,OACI,YAAAC,EACA,SAAAC,MACG,kDACP,OAAS,aAAAC,MAAiB,kDAE1B,OAAS,aAAAC,MAAiB,qCAC1B,MAAO,qDACP,MAAO,mEAEP,OAAOC,MAAkB,kBAEzB,MAAMC,EAAmBC,GAAuBA,EAAM,gBAAgB,EAS/D,aAAM,eAAeH,CAAU,CAA/B,kCAMH,KAAO,OAAS,GAGhB,KAAgB,MAAQ,SAMxB,KAAgB,YAAc,SAd9B,WAA2B,QAAyB,CAChD,MAAO,CAAC,GAAG,MAAM,OAAQC,CAAY,CACzC,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n nothing,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport { Textfield } from '@spectrum-web-components/textfield';\nimport '@spectrum-web-components/button/sp-clear-button.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js';\n\nimport searchStyles from './search.css.js';\n\nconst stopPropagation = (event: Event): void => event.stopPropagation();\n\n/**\n * @element sp-search\n * @slot help-text - default or non-negative help text to associate to your form element\n * @slot negative-help-text - negative help text to associate to your form element when `invalid`\n *\n * @fires submit - The search form has been submitted.\n */\nexport class Search extends Textfield {\n public static override get styles(): CSSResultArray {\n return [...super.styles, searchStyles];\n }\n\n @property()\n public action = '';\n\n @property()\n public override label = 'Search';\n\n @property()\n public method?: 'get' | 'post' | 'dialog';\n\n @property()\n public override placeholder = 'Search';\n\n @property({ type: Boolean })\n public holdValueOnEscape!: boolean;\n\n @query('#form')\n public form!: HTMLFormElement;\n\n private handleSubmit(event: Event): void {\n const applyDefault = this.dispatchEvent(\n new Event('submit', {\n cancelable: true,\n bubbles: true,\n })\n );\n if (!applyDefault) {\n event.preventDefault();\n }\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n if (code === 'Escape' && this.holdValueOnEscape) {\n return;\n }\n if (!this.value || code !== 'Escape') {\n return;\n }\n this.reset();\n }\n\n public async reset(): Promise<void> {\n this.value = '';\n await this.updateComplete;\n this.focusElement.dispatchEvent(\n new InputEvent('input', {\n bubbles: true,\n composed: true,\n })\n );\n // The native `change` event on an `input` element is not composed,\n // so this synthetic replication of a `change` event must not be\n // either as the `Textfield` baseclass should only need to handle\n // the native variant of this interaction.\n this.focusElement.dispatchEvent(\n new InputEvent('change', {\n bubbles: true,\n })\n );\n }\n\n protected override renderField(): TemplateResult {\n return html`\n <form\n action=${this.action}\n id=\"form\"\n method=${ifDefined(this.method)}\n @submit=${this.handleSubmit}\n @reset=${this.reset}\n @keydown=${this.handleKeydown}\n >\n <sp-icon-magnify\n class=\"icon magnifier icon-workflow icon-search\"\n ></sp-icon-magnify>\n ${super.renderField()}\n ${this.value\n ? html`\n <sp-clear-button\n id=\"button\"\n label=\"Reset\"\n tabindex=\"-1\"\n type=\"reset\"\n size=${ifDefined(this.size)}\n @keydown=${stopPropagation}\n ></sp-clear-button>\n `\n : nothing}\n </form>\n `;\n }\n\n public override firstUpdated(changedProperties: PropertyValues): void {\n super.firstUpdated(changedProperties);\n // if holdValueOnEscape is not set, default to search type\n if (!this.hasAttribute('holdValueOnEscape')) {\n this.inputElement.setAttribute('type', 'search');\n }\n }\n\n public override willUpdate(): void {\n this.multiline = false;\n }\n}\n"],
|
|
5
|
+
"mappings": "qNAYA,OAEI,QAAAA,EACA,WAAAC,MAGG,gCACP,OACI,YAAAC,EACA,SAAAC,MACG,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AiB,EAE/B,KAAK,aAAa,mBAAmB,GACtC,KAAK,aAAa,aAAa,OAAQ,QAAQ,CAEvD,CAEgB,YAAmB,CAC/B,KAAK,UAAY,EACrB,CACJ,CArGWC,EAAA,CADNT,EAAS,GALD,OAMF,sBAGSS,EAAA,CADfT,EAAS,GARD,OASO,qBAGTS,EAAA,CADNT,EAAS,GAXD,OAYF,sBAGSS,EAAA,CADfT,EAAS,GAdD,OAeO,2BAGTS,EAAA,CADNT,EAAS,CAAE,KAAM,OAAQ,CAAC,GAjBlB,OAkBF,iCAGAS,EAAA,CADNR,EAAM,OAAO,GApBL,OAqBF",
|
|
6
6
|
"names": ["html", "nothing", "property", "query", "ifDefined", "Textfield", "searchStyles", "stopPropagation", "event", "code", "changedProperties", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["search.stories.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2018 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport '@spectrum-web-components/search/sp-search.js';\nimport { html, TemplateResult } from '@spectrum-web-components/base';\n\nexport default {\n component: 'sp-search',\n title: 'Search',\n};\n\nexport const Default = (): TemplateResult => html`\n <sp-search></sp-search>\n <sp-search disabled></sp-search>\n`;\n\nexport const autofocus = (): TemplateResult => html`\n <sp-search autofocus></sp-search>\n`;\n\nexport const focusedOverflowing = (): TemplateResult => html`\n <sp-search\n value=\"this is a really long search term that overflows the available space\"\n ></sp-search>\n`;\n\nexport const Quiet = (): TemplateResult => html`\n <sp-search quiet></sp-search>\n <sp-search quiet disabled></sp-search>\n`;\n"],
|
|
5
|
-
"mappings": ";AAWA,OAAO;AACP,SAAS,YAA4B;AAErC,eAAe;AAAA,EACX,WAAW;AAAA,EACX,OAAO;AACX;AAEO,aAAM,UAAU,MAAsB;AAAA;AAAA;AAAA;AAKtC,aAAM,YAAY,MAAsB;AAAA;AAAA;AAIxC,aAAM,qBAAqB,MAAsB;AAAA;AAAA;AAAA;AAAA;AAMjD,aAAM,QAAQ,MAAsB;AAAA;AAAA;AAAA;",
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2018 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport '@spectrum-web-components/search/sp-search.js';\nimport { html, TemplateResult } from '@spectrum-web-components/base';\n\nexport default {\n component: 'sp-search',\n title: 'Search',\n};\n\nexport const Default = (): TemplateResult => html`\n <sp-search></sp-search>\n <sp-search disabled></sp-search>\n`;\n\nexport const autofocus = (): TemplateResult => html`\n <sp-search autofocus></sp-search>\n`;\n\nexport const focusedOverflowing = (): TemplateResult => html`\n <sp-search\n value=\"this is a really long search term that overflows the available space\"\n ></sp-search>\n`;\n\nexport const Quiet = (): TemplateResult => html`\n <sp-search quiet></sp-search>\n <sp-search quiet disabled></sp-search>\n`;\n\nexport const holdValueOnEscape = (): TemplateResult => html`\n <sp-search holdValueOnEscape></sp-search>\n`;\n"],
|
|
5
|
+
"mappings": ";AAWA,OAAO;AACP,SAAS,YAA4B;AAErC,eAAe;AAAA,EACX,WAAW;AAAA,EACX,OAAO;AACX;AAEO,aAAM,UAAU,MAAsB;AAAA;AAAA;AAAA;AAKtC,aAAM,YAAY,MAAsB;AAAA;AAAA;AAIxC,aAAM,qBAAqB,MAAsB;AAAA;AAAA;AAAA;AAAA;AAMjD,aAAM,QAAQ,MAAsB;AAAA;AAAA;AAAA;AAKpC,aAAM,oBAAoB,MAAsB;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/test/search.test.js
CHANGED
|
@@ -7,27 +7,21 @@ import { spy } from "sinon";
|
|
|
7
7
|
import { testForLitDevWarnings } from "../../../test/testing-helpers.js";
|
|
8
8
|
describe("Search", () => {
|
|
9
9
|
testForLitDevWarnings(
|
|
10
|
-
async () => await litFixture(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
`
|
|
14
|
-
)
|
|
10
|
+
async () => await litFixture(html`
|
|
11
|
+
<sp-search></sp-search>
|
|
12
|
+
`)
|
|
15
13
|
);
|
|
16
14
|
it("loads accessibly", async () => {
|
|
17
|
-
const el = await litFixture(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`
|
|
21
|
-
);
|
|
15
|
+
const el = await litFixture(html`
|
|
16
|
+
<sp-search></sp-search>
|
|
17
|
+
`);
|
|
22
18
|
await elementUpdated(el);
|
|
23
19
|
await expect(el).to.be.accessible();
|
|
24
20
|
});
|
|
25
21
|
it("can be cleared", async () => {
|
|
26
|
-
const el = await litFixture(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`
|
|
30
|
-
);
|
|
22
|
+
const el = await litFixture(html`
|
|
23
|
+
<sp-search value="Test"></sp-search>
|
|
24
|
+
`);
|
|
31
25
|
await elementUpdated(el);
|
|
32
26
|
expect(el.value).to.equal("Test");
|
|
33
27
|
const root = el.shadowRoot ? el.shadowRoot : el;
|
|
@@ -37,11 +31,9 @@ describe("Search", () => {
|
|
|
37
31
|
expect(el.value).to.equal("");
|
|
38
32
|
});
|
|
39
33
|
it("captures keyboard events to the clear button", async () => {
|
|
40
|
-
const el = await litFixture(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`
|
|
44
|
-
);
|
|
34
|
+
const el = await litFixture(html`
|
|
35
|
+
<sp-search value="Test"></sp-search>
|
|
36
|
+
`);
|
|
45
37
|
await elementUpdated(el);
|
|
46
38
|
expect(el.value).to.equal("Test");
|
|
47
39
|
const root = el.shadowRoot ? el.shadowRoot : el;
|
|
@@ -61,15 +53,13 @@ describe("Search", () => {
|
|
|
61
53
|
const target = event.target;
|
|
62
54
|
changeSpy(target.value);
|
|
63
55
|
};
|
|
64
|
-
const el = await litFixture(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
`
|
|
72
|
-
);
|
|
56
|
+
const el = await litFixture(html`
|
|
57
|
+
<sp-search
|
|
58
|
+
value="Test"
|
|
59
|
+
@change=${handleChange}
|
|
60
|
+
@input=${handleInput}
|
|
61
|
+
></sp-search>
|
|
62
|
+
`);
|
|
73
63
|
await elementUpdated(el);
|
|
74
64
|
expect(el.value).to.equal("Test");
|
|
75
65
|
const root = el.shadowRoot ? el.shadowRoot : el;
|
|
@@ -95,15 +85,13 @@ describe("Search", () => {
|
|
|
95
85
|
const target = event.target;
|
|
96
86
|
changeSpy(target.value);
|
|
97
87
|
};
|
|
98
|
-
const el = await litFixture(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
`
|
|
106
|
-
);
|
|
88
|
+
const el = await litFixture(html`
|
|
89
|
+
<sp-search
|
|
90
|
+
value="Test"
|
|
91
|
+
@change=${handleChange}
|
|
92
|
+
@input=${handleInput}
|
|
93
|
+
></sp-search>
|
|
94
|
+
`);
|
|
107
95
|
await elementUpdated(el);
|
|
108
96
|
expect(el.value).to.equal("Test");
|
|
109
97
|
el.focusElement.dispatchEvent(spaceEvent());
|
|
@@ -119,12 +107,40 @@ describe("Search", () => {
|
|
|
119
107
|
expect(changeSpy.calledOnce, "one change").to.be.true;
|
|
120
108
|
expect(changeSpy.calledWith(""), "was blank").to.be.true;
|
|
121
109
|
});
|
|
110
|
+
it('cannot be cleared via "Escape" if holdValueOnEscape is true', async () => {
|
|
111
|
+
const inputSpy = spy();
|
|
112
|
+
const changeSpy = spy();
|
|
113
|
+
const handleInput = (event) => {
|
|
114
|
+
const target = event.target;
|
|
115
|
+
inputSpy(target.value);
|
|
116
|
+
};
|
|
117
|
+
const handleChange = (event) => {
|
|
118
|
+
const target = event.target;
|
|
119
|
+
changeSpy(target.value);
|
|
120
|
+
};
|
|
121
|
+
const el = await litFixture(html`
|
|
122
|
+
<sp-search
|
|
123
|
+
value="Test"
|
|
124
|
+
@change=${handleChange}
|
|
125
|
+
@input=${handleInput}
|
|
126
|
+
holdValueOnEscape
|
|
127
|
+
></sp-search>
|
|
128
|
+
`);
|
|
129
|
+
await elementUpdated(el);
|
|
130
|
+
expect(el.value).to.equal("Test");
|
|
131
|
+
el.focusElement.dispatchEvent(spaceEvent());
|
|
132
|
+
await elementUpdated(el);
|
|
133
|
+
expect(el.value).to.equal("Test");
|
|
134
|
+
inputSpy.resetHistory();
|
|
135
|
+
changeSpy.resetHistory();
|
|
136
|
+
el.focusElement.dispatchEvent(escapeEvent());
|
|
137
|
+
await elementUpdated(el);
|
|
138
|
+
expect(el.value).to.equal("Test");
|
|
139
|
+
});
|
|
122
140
|
it("cannot be multiline", async () => {
|
|
123
|
-
const el = await litFixture(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
`
|
|
127
|
-
);
|
|
141
|
+
const el = await litFixture(html`
|
|
142
|
+
<sp-search multiline></sp-search>
|
|
143
|
+
`);
|
|
128
144
|
await elementUpdated(el);
|
|
129
145
|
expect(el.multiline).to.be.false;
|
|
130
146
|
el.multiline = true;
|
|
@@ -133,11 +149,9 @@ describe("Search", () => {
|
|
|
133
149
|
});
|
|
134
150
|
it("accepts `placeholder` and `label` properties", async () => {
|
|
135
151
|
const testString = "Search for images";
|
|
136
|
-
const el = await litFixture(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
`
|
|
140
|
-
);
|
|
152
|
+
const el = await litFixture(html`
|
|
153
|
+
<sp-search></sp-search>
|
|
154
|
+
`);
|
|
141
155
|
await elementUpdated(el);
|
|
142
156
|
el.placeholder = testString;
|
|
143
157
|
el.label = testString;
|
|
@@ -146,15 +160,13 @@ describe("Search", () => {
|
|
|
146
160
|
expect(el.focusElement.getAttribute("aria-label")).to.equal(testString);
|
|
147
161
|
});
|
|
148
162
|
it("can have default prevented", async () => {
|
|
149
|
-
const el = await litFixture(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
`
|
|
157
|
-
);
|
|
163
|
+
const el = await litFixture(html`
|
|
164
|
+
<sp-search
|
|
165
|
+
@submit=${(event) => {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
}}
|
|
168
|
+
></sp-search>
|
|
169
|
+
`);
|
|
158
170
|
await elementUpdated(el);
|
|
159
171
|
const searchForm = el.shadowRoot ? el.shadowRoot.querySelector("form") : el.querySelector("form");
|
|
160
172
|
const submitEvent = new Event("submit", {
|
package/test/search.test.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["search.test.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport '@spectrum-web-components/search/sp-search.js';\nimport { Search } from '@spectrum-web-components/search';\nimport { elementUpdated, expect, html, litFixture } from '@open-wc/testing';\nimport { escapeEvent, spaceEvent } from '../../../test/testing-helpers.js';\nimport '@spectrum-web-components/shared/src/focus-visible.js';\nimport { spy } from 'sinon';\nimport { testForLitDevWarnings } from '../../../test/testing-helpers.js';\n\ndescribe('Search', () => {\n testForLitDevWarnings(\n async () =>\n await litFixture<Search>(
|
|
5
|
-
"mappings": ";AAWA,OAAO;AAEP,SAAS,gBAAgB,QAAQ,MAAM,kBAAkB;AACzD,SAAS,aAAa,kBAAkB;AACxC,OAAO;AACP,SAAS,WAAW;AACpB,SAAS,6BAA6B;AAEtC,SAAS,UAAU,MAAM;AACrB;AAAA,IACI,YACI,MAAM
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport '@spectrum-web-components/search/sp-search.js';\nimport { Search } from '@spectrum-web-components/search';\nimport { elementUpdated, expect, html, litFixture } from '@open-wc/testing';\nimport { escapeEvent, spaceEvent } from '../../../test/testing-helpers.js';\nimport '@spectrum-web-components/shared/src/focus-visible.js';\nimport { spy } from 'sinon';\nimport { testForLitDevWarnings } from '../../../test/testing-helpers.js';\n\ndescribe('Search', () => {\n testForLitDevWarnings(\n async () =>\n await litFixture<Search>(html`\n <sp-search></sp-search>\n `)\n );\n it('loads accessibly', async () => {\n const el = await litFixture<Search>(html`\n <sp-search></sp-search>\n `);\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n it('can be cleared', async () => {\n const el = await litFixture<Search>(html`\n <sp-search value=\"Test\"></sp-search>\n `);\n\n await elementUpdated(el);\n expect(el.value).to.equal('Test');\n\n const root = el.shadowRoot ? el.shadowRoot : el;\n const clearButton = root.querySelector('#button') as HTMLButtonElement;\n clearButton.click();\n\n await elementUpdated(el);\n\n expect(el.value).to.equal('');\n });\n it('captures keyboard events to the clear button', async () => {\n const el = await litFixture<Search>(html`\n <sp-search value=\"Test\"></sp-search>\n `);\n\n await elementUpdated(el);\n expect(el.value).to.equal('Test');\n\n const root = el.shadowRoot ? el.shadowRoot : el;\n const clearButton = root.querySelector('#button') as HTMLButtonElement;\n clearButton.dispatchEvent(escapeEvent());\n\n await elementUpdated(el);\n\n expect(el.value).to.equal('Test');\n });\n it('dispatches events when using the \"clear\" button', async () => {\n const inputSpy = spy();\n const changeSpy = spy();\n const handleInput = (event: Event): void => {\n const target = event.target as HTMLInputElement;\n inputSpy(target.value);\n };\n const handleChange = (event: Event): void => {\n const target = event.target as HTMLInputElement;\n changeSpy(target.value);\n };\n const el = await litFixture<Search>(html`\n <sp-search\n value=\"Test\"\n @change=${handleChange}\n @input=${handleInput}\n ></sp-search>\n `);\n\n await elementUpdated(el);\n expect(el.value).to.equal('Test');\n\n const root = el.shadowRoot ? el.shadowRoot : el;\n const clearButton = root.querySelector('#button') as HTMLButtonElement;\n inputSpy.resetHistory();\n changeSpy.resetHistory();\n clearButton.click();\n\n await elementUpdated(el);\n\n expect(el.value).to.equal('');\n expect(inputSpy.calledOnce, 'one input').to.be.true;\n expect(inputSpy.calledWith(''), 'was blank').to.be.true;\n expect(changeSpy.calledOnce, 'one change').to.be.true;\n expect(changeSpy.calledWith(''), 'was blank').to.be.true;\n });\n it('can be cleared via \"Escape\"', async () => {\n const inputSpy = spy();\n const changeSpy = spy();\n const handleInput = (event: Event): void => {\n const target = event.target as HTMLInputElement;\n inputSpy(target.value);\n };\n const handleChange = (event: Event): void => {\n const target = event.target as HTMLInputElement;\n changeSpy(target.value);\n };\n const el = await litFixture<Search>(html`\n <sp-search\n value=\"Test\"\n @change=${handleChange}\n @input=${handleInput}\n ></sp-search>\n `);\n\n await elementUpdated(el);\n expect(el.value).to.equal('Test');\n el.focusElement.dispatchEvent(spaceEvent());\n\n await elementUpdated(el);\n expect(el.value).to.equal('Test');\n\n inputSpy.resetHistory();\n changeSpy.resetHistory();\n el.focusElement.dispatchEvent(escapeEvent());\n\n await elementUpdated(el);\n\n expect(el.value).to.equal('');\n expect(inputSpy.calledOnce, 'one input').to.be.true;\n expect(inputSpy.calledWith(''), 'was blank').to.be.true;\n expect(changeSpy.calledOnce, 'one change').to.be.true;\n expect(changeSpy.calledWith(''), 'was blank').to.be.true;\n });\n it('cannot be cleared via \"Escape\" if holdValueOnEscape is true', async () => {\n const inputSpy = spy();\n const changeSpy = spy();\n const handleInput = (event: Event): void => {\n const target = event.target as HTMLInputElement;\n inputSpy(target.value);\n };\n const handleChange = (event: Event): void => {\n const target = event.target as HTMLInputElement;\n changeSpy(target.value);\n };\n const el = await litFixture<Search>(html`\n <sp-search\n value=\"Test\"\n @change=${handleChange}\n @input=${handleInput}\n holdValueOnEscape\n ></sp-search>\n `);\n\n await elementUpdated(el);\n expect(el.value).to.equal('Test');\n el.focusElement.dispatchEvent(spaceEvent());\n\n await elementUpdated(el);\n expect(el.value).to.equal('Test');\n\n inputSpy.resetHistory();\n changeSpy.resetHistory();\n el.focusElement.dispatchEvent(escapeEvent());\n\n await elementUpdated(el);\n\n expect(el.value).to.equal('Test');\n });\n it('cannot be multiline', async () => {\n const el = await litFixture<Search>(html`\n <sp-search multiline></sp-search>\n `);\n\n await elementUpdated(el);\n\n expect(el.multiline).to.be.false;\n\n el.multiline = true;\n\n await elementUpdated(el);\n\n expect(el.multiline).to.be.false;\n });\n it('accepts `placeholder` and `label` properties', async () => {\n const testString = 'Search for images';\n const el = await litFixture<Search>(html`\n <sp-search></sp-search>\n `);\n\n await elementUpdated(el);\n el.placeholder = testString;\n el.label = testString;\n\n await elementUpdated(el);\n\n expect(el.focusElement.placeholder).to.equal(testString);\n expect(el.focusElement.getAttribute('aria-label')).to.equal(testString);\n });\n it('can have default prevented', async () => {\n const el = await litFixture<Search>(html`\n <sp-search\n @submit=${(event: Event) => {\n event.preventDefault();\n }}\n ></sp-search>\n `);\n\n await elementUpdated(el);\n const searchForm = (\n el.shadowRoot\n ? el.shadowRoot.querySelector('form')\n : el.querySelector('form')\n ) as HTMLFormElement;\n\n const submitEvent = new Event('submit', {\n cancelable: true,\n bubbles: false,\n composed: false,\n });\n searchForm.dispatchEvent(submitEvent);\n\n expect(submitEvent.defaultPrevented).to.be.true;\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAWA,OAAO;AAEP,SAAS,gBAAgB,QAAQ,MAAM,kBAAkB;AACzD,SAAS,aAAa,kBAAkB;AACxC,OAAO;AACP,SAAS,WAAW;AACpB,SAAS,6BAA6B;AAEtC,SAAS,UAAU,MAAM;AACrB;AAAA,IACI,YACI,MAAM,WAAmB;AAAA;AAAA,aAExB;AAAA,EACT;AACA,KAAG,oBAAoB,YAAY;AAC/B,UAAM,KAAK,MAAM,WAAmB;AAAA;AAAA,SAEnC;AAED,UAAM,eAAe,EAAE;AAEvB,UAAM,OAAO,EAAE,EAAE,GAAG,GAAG,WAAW;AAAA,EACtC,CAAC;AACD,KAAG,kBAAkB,YAAY;AAC7B,UAAM,KAAK,MAAM,WAAmB;AAAA;AAAA,SAEnC;AAED,UAAM,eAAe,EAAE;AACvB,WAAO,GAAG,KAAK,EAAE,GAAG,MAAM,MAAM;AAEhC,UAAM,OAAO,GAAG,aAAa,GAAG,aAAa;AAC7C,UAAM,cAAc,KAAK,cAAc,SAAS;AAChD,gBAAY,MAAM;AAElB,UAAM,eAAe,EAAE;AAEvB,WAAO,GAAG,KAAK,EAAE,GAAG,MAAM,EAAE;AAAA,EAChC,CAAC;AACD,KAAG,gDAAgD,YAAY;AAC3D,UAAM,KAAK,MAAM,WAAmB;AAAA;AAAA,SAEnC;AAED,UAAM,eAAe,EAAE;AACvB,WAAO,GAAG,KAAK,EAAE,GAAG,MAAM,MAAM;AAEhC,UAAM,OAAO,GAAG,aAAa,GAAG,aAAa;AAC7C,UAAM,cAAc,KAAK,cAAc,SAAS;AAChD,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