mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 10:37:56 +00:00 
			
		
		
		
	![hashicorp-copywrite[bot]](/assets/img/avatar_default.png) 0b12cdcfd1
			
		
	
	0b12cdcfd1
	
	
	
		
			
			* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /**
 | |
|  * Copyright (c) HashiCorp, Inc.
 | |
|  * SPDX-License-Identifier: BUSL-1.1
 | |
|  */
 | |
| 
 | |
| import Component from '@glimmer/component';
 | |
| import { action } from '@ember/object';
 | |
| 
 | |
| /**
 | |
|  * @module AutocompleteInput
 | |
|  * AutocompleteInput components are used as standard string inputs or optionally select options to append to input value
 | |
|  *
 | |
|  * @example
 | |
|  * ```js
 | |
|  * <AutocompleteInput @requiredParam={requiredParam} @optionalParam={optionalParam} @param1={{param1}}/>
 | |
|  * ```
 | |
|  * @callback inputChangeCallback
 | |
|  * @param {string} value - input value
 | |
|  * @param {inputChangeCallback} onChange - fires when input value changes to mutate value param by caller
 | |
|  * @param {string} [optionsTrigger] - display options dropdown when trigger character is input
 | |
|  * @param {Object[]} [options] - array of { label, value } objects where label is displayed in options dropdown and value is appended to input value
 | |
|  * @param {string} [label] - label to display above input
 | |
|  * @param {string} [subText] - text to display below label
 | |
|  * @param {string} [placeholder] - input placeholder
 | |
|  */
 | |
| 
 | |
| export default class AutocompleteInput extends Component {
 | |
|   dropdownAPI;
 | |
|   inputElement;
 | |
| 
 | |
|   @action
 | |
|   setElement(element) {
 | |
|     this.inputElement = element.querySelector('.input');
 | |
|   }
 | |
|   @action
 | |
|   setDropdownAPI(dropdownAPI) {
 | |
|     this.dropdownAPI = dropdownAPI;
 | |
|   }
 | |
|   @action
 | |
|   onInput(event) {
 | |
|     const { options = [], optionsTrigger } = this.args;
 | |
|     if (optionsTrigger && options.length) {
 | |
|       const method = event.data === optionsTrigger ? 'open' : 'close';
 | |
|       this.dropdownAPI.actions[method]();
 | |
|     }
 | |
|     this.args.onChange(event.target.value);
 | |
|   }
 | |
|   @action
 | |
|   selectOption(value) {
 | |
|     // if trigger character is at start of value it needs to be trimmed
 | |
|     const appendValue = value.startsWith(this.args.optionsTrigger) ? value.slice(1) : value;
 | |
|     const newValue = this.args.value + appendValue;
 | |
|     this.args.onChange(newValue);
 | |
|     this.dropdownAPI.actions.close();
 | |
|     this.inputElement.focus();
 | |
|   }
 | |
| }
 |