-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use new apis for trigger/input component from ember-power-select
- Loading branch information
1 parent
e6b8e2e
commit 284738f
Showing
5 changed files
with
137 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 1 addition & 55 deletions
56
packages/core/addon/components/eui-combo-box/trigger/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,3 @@ | ||
import EmberPowerSelectMultipleTrigger from 'ember-power-select/components/power-select-multiple/trigger'; | ||
import { action } from '@ember/object'; | ||
import { isBlank } from '@ember/utils'; | ||
import { scheduleOnce } from '@ember/runloop'; | ||
import { htmlSafe } from '@ember/template'; | ||
|
||
export default class EuiComboBoxTriggerComponent extends EmberPowerSelectMultipleTrigger { | ||
get triggerMultipleInputStyle() { | ||
scheduleOnce('actions', null, this.args.select.actions.reposition); | ||
|
||
let textWidth = 0; | ||
if (this.inputFont) { | ||
textWidth = this.textMeasurer.width( | ||
this.args.select.searchText, | ||
this.inputFont | ||
); | ||
} | ||
return htmlSafe(`box-sizing: content-box; width: ${textWidth + 2}px`); | ||
} | ||
|
||
@action | ||
handleKeydown(e) { | ||
if (e.target === null) return; | ||
if (this.args.onKeydown && this.args.onKeydown(e) === false) { | ||
if ( | ||
this.args.onCreateOption && //if user wants to create an option and | ||
e.keyCode === 13 && //presses [Enter] and | ||
(this.args.select.options.length === 0 || //If There are no options or | ||
this.args.select.results.length === 0) && //Last search made returned no results and | ||
this.args.select.searchText.length >= 1 //There's something in the searchText box | ||
) { | ||
this.args.onCreateOption(); | ||
return false; | ||
} | ||
e.stopPropagation(); | ||
return false; | ||
} | ||
if (e.keyCode === 8) { | ||
e.stopPropagation(); | ||
if (isBlank(e.target.value)) { | ||
let lastSelection = | ||
this.args.select.selected[this.args.select.selected.length - 1]; | ||
if (lastSelection) { | ||
this.args.select.actions.select( | ||
this.args.buildSelection(lastSelection, this.args.select), | ||
e | ||
); | ||
this.args.select.actions.search(''); | ||
this.args.select.actions.open(e); | ||
} | ||
} | ||
} else if ((e.keyCode >= 48 && e.keyCode <= 90) || e.keyCode === 32) { | ||
// Keys 0-9, a-z or SPACE | ||
e.stopPropagation(); | ||
} | ||
} | ||
} | ||
export default class EuiComboBoxTriggerComponent extends EmberPowerSelectMultipleTrigger {} |
38 changes: 38 additions & 0 deletions
38
packages/core/addon/components/eui-combo-box/trigger/input/index.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{{!template-lint-disable}} | ||
{{#if (and this.maybePlaceholder (not @select.searchText))}} | ||
<p class="euiComboBoxPlaceholder"> | ||
{{this.maybePlaceholder}} | ||
</p> | ||
{{/if}} | ||
<div | ||
class="euiComboBox__input" | ||
style="font-size: 14px; display: inline-block; position: relative;" | ||
> | ||
<input | ||
tabindex="-1" | ||
style="opacity: 0px; width:0px; height:0px; position: absolute; top: 40%; border:solid 1px transparent !important; margin:0px !important;" | ||
class="fake-input-for-html-form-validity" | ||
{{validatable-control @isInvalid}} | ||
/> | ||
<input | ||
class="ember-power-select-trigger-multiple-input euiComboBox__input" | ||
autocomplete="off" | ||
autocorrect="off" | ||
autocapitalize="off" | ||
autofocus={{@autoFocus}} | ||
spellcheck={{false}} | ||
id="ember-power-select-trigger-multiple-input-{{@select.uniqueId}}" | ||
value={{@select.searchText}} | ||
aria-controls={{@listboxId}} | ||
style={{this.triggerMultipleInputStyle}} | ||
disabled={{@select.disabled}} | ||
tabindex={{@tabindex}} | ||
form="power-select-fake-form" | ||
{{on "focus" @onFocus}} | ||
{{on "blur" @onBlur}} | ||
{{on "input" this.handleInput}} | ||
{{on "keydown" this.handleKeydown}} | ||
{{did-insert this.storeInputStyles}} | ||
/> | ||
</div> | ||
{{!template-lint-enable}} |
63 changes: 63 additions & 0 deletions
63
packages/core/addon/components/eui-combo-box/trigger/input/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import EmberPowerSelectPowerSelectMultipleTriggerInputComponent from 'ember-power-select/components/power-select-multiple/input'; | ||
import { action } from '@ember/object'; | ||
import { isBlank } from '@ember/utils'; | ||
|
||
import { htmlSafe } from '@ember/template'; | ||
|
||
import { scheduleOnce } from '@ember/runloop'; | ||
|
||
export default class EuiComboBoxTriggerInputComponent extends EmberPowerSelectPowerSelectMultipleTriggerInputComponent { | ||
get triggerMultipleInputStyle() { | ||
scheduleOnce('actions', null, this.args.select.actions.reposition); | ||
|
||
let textWidth = 0; | ||
// @ts-expect-error | ||
if (this.inputFont) { | ||
textWidth = this.textMeasurer.width( | ||
this.args.select.searchText, | ||
// @ts-expect-error | ||
this.inputFont | ||
); | ||
} | ||
return htmlSafe(`box-sizing: content-box; width: ${textWidth + 2}px`); | ||
} | ||
|
||
@action | ||
handleKeydown(e: KeyboardEvent): false | void { | ||
if (e.target === null) return; | ||
if (this.args.onKeydown && this.args.onKeydown(e) === false) { | ||
if ( | ||
// @ts-expect-error | ||
this.args.onCreateOption && //if user wants to create an option and | ||
e.keyCode === 13 && //presses [Enter] and | ||
(this.args.select.options.length === 0 || //If There are no options or | ||
this.args.select.results.length === 0) && //Last search made returned no results and | ||
this.args.select.searchText.length >= 1 //There's something in the searchText box | ||
) { | ||
// @ts-expect-error | ||
this.args.onCreateOption(); | ||
return false; | ||
} | ||
e.stopPropagation(); | ||
return false; | ||
} | ||
if (e.keyCode === 8) { | ||
e.stopPropagation(); | ||
if (isBlank((e.target as HTMLInputElement).value)) { | ||
let lastSelection = | ||
this.args.select.selected[this.args.select.selected.length - 1]; | ||
if (lastSelection) { | ||
this.args.select.actions.select( | ||
this.args.buildSelection(lastSelection, this.args.select), | ||
e | ||
); | ||
this.args.select.actions.search(''); | ||
this.args.select.actions.open(e); | ||
} | ||
} | ||
} else if ((e.keyCode >= 48 && e.keyCode <= 90) || e.keyCode === 32) { | ||
// Keys 0-9, a-z or SPACE | ||
e.stopPropagation(); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/core/app/components/eui-combo-box/trigger/input/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '@ember-eui/core/components/eui-combo-box/trigger/input'; |