diff --git a/CHANGELOG.md b/CHANGELOG.md index ff82907c..a2f2fddb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.5.5] - 2022-02-09 ### Changed - +- [#212](https://github.com/equinor/webviz-core-components/pull/212) - Changed `tab` behaviour in `SmartNodeSelector`. When pressing `tab` on the last tag or `shift+tab` on the first one, the default behaviour is no longer prevented. - [#197](https://github.com/equinor/webviz-core-components/pull/197) - Updated `@equinor/eds-icons` (and associated `@equinor/eds-core-react` dependencies) in order to use new icons upstream in the application menu. ## [0.5.4] - 2021-12-09 diff --git a/react/src/lib/components/SmartNodeSelector/components/SmartNodeSelectorComponent.tsx b/react/src/lib/components/SmartNodeSelector/components/SmartNodeSelectorComponent.tsx index 1e6bd402..fc481141 100644 --- a/react/src/lib/components/SmartNodeSelector/components/SmartNodeSelectorComponent.tsx +++ b/react/src/lib/components/SmartNodeSelector/components/SmartNodeSelectorComponent.tsx @@ -111,6 +111,7 @@ export default class SmartNodeSelectorComponent extends Component; @@ -154,6 +155,7 @@ export default class SmartNodeSelectorComponent extends Component= 0 && index < this.countTags()) { if (this.state.nodeSelections.length > index && index >= 0) { - const inputField = (this.state.nodeSelections[ - index - ]?.getRef() as React.RefObject).current; + const inputField = ( + this.state.nodeSelections[ + index + ]?.getRef() as React.RefObject + ).current; if (inputField) { inputField.focus(); if (setSelection !== undefined) { @@ -404,9 +408,8 @@ export default class SmartNodeSelectorComponent extends Component) - .current === document.activeElement + ( + this.currentNodeSelection().getRef() as React.RefObject + ).current === document.activeElement ) { this.updateState({ suggestionsVisible: true, @@ -656,9 +660,9 @@ export default class SmartNodeSelectorComponent extends Component) - .current as HTMLDivElement; + const numberOfTagsDiv = ( + this.refNumberOfTags as React.RefObject + ).current as HTMLDivElement; const blinkTimer = setInterval(() => { numBlinks++; if (numBlinks % 2 === 0) { @@ -675,6 +679,19 @@ export default class SmartNodeSelectorComponent extends Component) .current as HTMLUListElement; - const suggestions = (this - .suggestionsRef as React.RefObject) - .current as HTMLDivElement; + const suggestions = ( + this.suggestionsRef as React.RefObject + ).current as HTMLDivElement; const eventTarget = event.target as Element; if ( (!domNode || !domNode.contains(eventTarget)) && @@ -738,6 +755,8 @@ export default class SmartNodeSelectorComponent extends Component { - ((this.state.nodeSelections[0].getRef() as React.RefObject) - .current as HTMLInputElement).focus(); + ( + ( + this.state.nodeSelections[0].getRef() as React.RefObject + ).current as HTMLInputElement + ).focus(); }, }); e.stopPropagation(); @@ -1119,7 +1141,8 @@ export default class SmartNodeSelectorComponent extends Component= maxNumSelectedNodes && @@ -1332,8 +1355,9 @@ export default class SmartNodeSelectorComponent extends Component { - const input = (this.currentNodeSelection()?.getRef() as React.RefObject) - ?.current; + const input = ( + this.currentNodeSelection()?.getRef() as React.RefObject + )?.current; if (input) { input.setSelectionRange(0, 0); } @@ -1564,11 +1588,56 @@ export default class SmartNodeSelectorComponent extends Component { + if (!this.selectionHasStarted) { + this.unselectAllTags({}); + + this.updateState({ currentTagIndex: -1 }); + } + this.selectionHasStarted = false; + }, + }); + return; + } + if ( + !e.shiftKey && + this.currentTagIndex() === this.countTags() - 1 + ) { + this.hideSuggestions({ + callback: () => { + if (!this.selectionHasStarted) { + this.unselectAllTags({}); + + this.updateState({ currentTagIndex: -1 }); + } + this.selectionHasStarted = false; + }, + }); + return; + } + + if (e.shiftKey) { + this.decrementCurrentTagIndex(() => this.focusCurrentTag()); + } else { + this.incrementCurrentTagIndex(() => this.focusCurrentTag()); + } + } + } else if (this.tabbedInFromOutside) { if (e.shiftKey) { - this.decrementCurrentTagIndex(() => this.focusCurrentTag()); + this.updateState({ + currentTagIndex: this.countTags() - 1, + callback: () => this.focusCurrentTag(Direction.Right), + }); } else { - this.incrementCurrentTagIndex(() => this.focusCurrentTag()); + this.updateState({ + currentTagIndex: 0, + callback: () => this.focusCurrentTag(Direction.Right), + }); } + this.tabbedInFromOutside = false; } e.preventDefault(); } @@ -1873,7 +1942,8 @@ export default class SmartNodeSelectorComponent extends Component 0 && this.countValidSelections() > maxNumSelectedNodes,