From 1f002802fc2396f1476fa71a690d4e1078048c03 Mon Sep 17 00:00:00 2001 From: Arlston Fernandes Date: Mon, 14 Jun 2021 18:10:15 +0100 Subject: [PATCH 1/3] Handle query change when the text length does not change --- src/autocomplete.js | 2 +- test/functional/index.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/autocomplete.js b/src/autocomplete.js index 0ca9a332..dd029b0f 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -215,7 +215,7 @@ export default class Autocomplete extends Component { const autoselect = this.hasAutoselect() const query = event.target.value const queryEmpty = query.length === 0 - const queryChanged = this.state.query.length !== query.length + const queryChanged = this.state.query !== query const queryLongEnough = query.length >= minLength this.setState({ diff --git a/test/functional/index.js b/test/functional/index.js index 4c759c3c..bf865b5c 100644 --- a/test/functional/index.js +++ b/test/functional/index.js @@ -194,6 +194,12 @@ describe('Autocomplete', () => { expect(autocomplete.state.menuOpen).to.equal(false) }) + it('searches with the new term when query length changes', () => { + autocomplete.setState({ query: 'fr', options: ['France'] }) + autocomplete.handleInputChange({ target: { value: 'fb' } }) + expect(autocomplete.state.options.length).to.equal(0) + }) + it('removes the aria-describedby attribute when query is non empty', () => { expect(autocomplete.state.ariaHint).to.equal(true) autocomplete.handleInputChange({ target: { value: 'a' } }) From 641a12f33644ada1f2e183d1dc2c503b4a53e042 Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Fri, 12 Jan 2024 12:35:34 +0000 Subject: [PATCH 2/3] Rebuild dist --- dist/accessible-autocomplete.min.js | 2 +- dist/accessible-autocomplete.min.js.map | 2 +- dist/lib/accessible-autocomplete.preact.min.js | 2 +- dist/lib/accessible-autocomplete.preact.min.js.map | 2 +- dist/lib/accessible-autocomplete.react.min.js | 2 +- dist/lib/accessible-autocomplete.react.min.js.map | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/accessible-autocomplete.min.js b/dist/accessible-autocomplete.min.js index f12e9840..98df3221 100644 --- a/dist/accessible-autocomplete.min.js +++ b/dist/accessible-autocomplete.min.js @@ -1,2 +1,2 @@ -(function webpackUniversalModuleDefinition(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["accessibleAutocomplete"]=t():e["accessibleAutocomplete"]=t()})(window,function(){return function(n){var r={};function o(e){if(r[e])return r[e].exports;var t=r[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}return o.m=n,o.c=r,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/",o(o.s=37)}([function(e,t,n){var m=n(1),v=n(6),y=n(7),_=n(16),g=n(18),b="prototype",w=function(e,t,n){var r,o,i,u,a=e&w.F,s=e&w.G,l=e&w.S,c=e&w.P,p=e&w.B,f=s?m:l?m[t]||(m[t]={}):(m[t]||{})[b],d=s?v:v[t]||(v[t]={}),h=d[b]||(d[b]={});for(r in s&&(n=t),n)i=((o=!a&&f&&f[r]!==undefined)?f:n)[r],u=p&&o?g(i,m):c&&"function"==typeof i?g(Function.call,i):i,f&&_(f,r,i,e&w.U),d[r]!=i&&y(d,r,u),c&&h[r]!=i&&(h[r]=i)};m.core=v,w.F=1,w.G=2,w.S=4,w.P=8,w.B=16,w.W=32,w.U=64,w.R=128,e.exports=w},function(e,t){var n=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(e,t){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,t,n){e.exports=!n(4)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(e,t){e.exports=function(e){try{return!!e()}catch(t){return!0}}},function(e,t,n){"use strict";n.r(t),n.d(t,"h",function(){return r}),n.d(t,"createElement",function(){return r}),n.d(t,"cloneElement",function(){return i}),n.d(t,"Component",function(){return _}),n.d(t,"render",function(){return g}),n.d(t,"rerender",function(){return f}),n.d(t,"options",function(){return E});var s=function s(){},E={},l=[],c=[];function r(e,t){var n,r,o,i,u=c;for(i=arguments.length;2o;)u(r,n=t[o++])&&(~s(i,n)||i.push(n));return i}},function(e,t,n){var r=n(25),o=Math.max,i=Math.min;e.exports=function(e,t){return(e=r(e))<0?o(e+t,0):i(e,t)}},function(e,t){e.exports=!1},function(e,t){t.f=Object.getOwnPropertySymbols},function(e,t){t.f={}.propertyIsEnumerable},function(e,t,n){var r=n(48);e.exports=function(e,t){return new(r(e))(t)}},function(e,t,n){var r=n(2),o=n(33),i=n(34)("species");e.exports=function(e){var t;return o(e)&&("function"!=typeof(t=e.constructor)||t!==Array&&!o(t.prototype)||(t=undefined),r(t)&&null===(t=t[i])&&(t=undefined)),t===undefined?Array:t}},function(e,t,n){"use strict";var r=n(0),o=n(32)(2);r(r.P+r.F*!n(13)([].filter,!0),"Array",{filter:function(e){return o(this,e,arguments[1])}})},function(e,t,n){var r=n(0);r(r.S,"Array",{isArray:n(33)})},function(e,t,n){"use strict";t.__esModule=!0,t["default"]=void 0,n(14),n(36),n(30),n(31),n(35),n(55),n(58);var X=n(5),Y=o(n(60)),r=o(n(61));function o(e){return e&&e.__esModule?e:{"default":e}}function Z(){return(Z=Object.assign||function(e){for(var t=1;t=r;this.setState({query:a,ariaHint:s}),i||!s&&l&&c?o(a,function(e){var t=0=i&&0=o,j=this.props.showNoOptionsFound&&A&&I&&k&&P,L=n+"__wrapper",T=n+"__input",B=n+"__status",D=null!==b?" "+T+"--focused":"",F=this.props.showAllValues?" "+T+"--show-all-values":" "+T+"--default",R=n+"__dropdown-arrow-down",U=-1!==b&&null!==b,V=n+"__menu",q=V+"--"+r,W=V+"--"+(x||j?"visible":"hidden"),H=n+"__option",K=n+"__hint",Q=this.templateInputValue(O[S]),z=Q&&0===Q.toLowerCase().indexOf(C.toLowerCase())&&M?C+Q.substr(C.length):"",G=u+"__assistiveHint",$=E?{"aria-describedby":G}:null;return c&&"string"==typeof(e=y({className:R}))&&(e=(0,X.createElement)("div",{className:n+"__dropdown-arrow-down-wrapper",dangerouslySetInnerHTML:{__html:e}})),(0,X.createElement)("div",{className:L,onKeyDown:this.handleKeyDown},(0,X.createElement)(Y["default"],{id:u,length:O.length,queryLength:C.length,minQueryLength:o,selectedOption:this.templateInputValue(O[S]),selectedOptionIndex:S,validChoiceMade:N,isInFocus:null!==this.state.focused,tQueryTooShort:f,tNoResults:d,tSelectedOption:h,tResults:m,className:B}),z&&(0,X.createElement)("span",null,(0,X.createElement)("input",{className:K,readonly:!0,tabIndex:"-1",value:z})),(0,X.createElement)("input",Z({"aria-expanded":x?"true":"false","aria-activedescendant":!!U&&u+"__option--"+b,"aria-owns":u+"__listbox","aria-autocomplete":this.hasAutoselect()?"both":"list"},$,{autoComplete:"off",className:""+T+D+F,id:u,onClick:function(e){return i.handleInputClick(e)},onBlur:this.handleInputBlur},function J(e){return{onInput:e}}(this.handleInputChange),{onFocus:this.handleInputFocus,name:a,placeholder:s,ref:function(e){i.elementReferences[-1]=e},type:"text",role:"combobox",required:l,value:C})),e,(0,X.createElement)("ul",Z({className:V+" "+q+" "+W,onMouseLeave:function(e){return i.handleListMouseLeave(e)},id:u+"__listbox",role:"listbox"},_),O.map(function(e,t){var n=(-1===b?S===t:b===t)&&null===w?" "+H+"--focused":"",r=t%2?" "+H+"--odd":"",o=ee()?" '+(t+1)+" of "+O.length+"":"";return(0,X.createElement)("li",{"aria-selected":b===t?"true":"false",className:""+H+n+r,dangerouslySetInnerHTML:{__html:i.templateSuggestion(e)+o},id:u+"__option--"+t,key:t,onBlur:function(e){return i.handleOptionBlur(e,t)},onClick:function(e){return i.handleOptionClick(e,t)},onMouseDown:i.handleOptionMouseDown,onMouseEnter:function(e){return i.handleOptionMouseEnter(e,t)},ref:function(e){i.elementReferences[t]=e},role:"option",tabIndex:"-1","aria-posinset":t+1,"aria-setsize":O.length})}),j&&(0,X.createElement)("li",{className:H+" "+H+"--no-results"},p())),(0,X.createElement)("span",{id:G,style:{display:"none"}},v()))},e}(X.Component);(t["default"]=a).defaultProps={autoselect:!1,cssNamespace:"autocomplete",defaultValue:"",displayMenu:"inline",minLength:0,name:"input-autocomplete",placeholder:"",onConfirm:function(){},confirmOnBlur:!0,showNoOptionsFound:!0,showAllValues:!1,required:!1,tNoResults:function(){return"No results found"},tAssistiveHint:function(){return"When autocomplete results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures."},dropdownArrow:r["default"],menuAttributes:{}}},function(e,t,r){var o=r(9),i=r(53),u=r(28),a=r(26)("IE_PROTO"),s=function(){},l="prototype",c=function(){var e,t=r(15)("iframe"),n=u.length;for(t.style.display="none",r(54).appendChild(t),t.src="javascript:",(e=t.contentWindow.document).open(),e.write("