Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(addon/components/paper-input): converts to a glimmer component. #1312

Open
wants to merge 4 commits into
base: feature/glimmer-paper-tabs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions addon/components/-focusable.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export default class Focusable extends Component {
* They bubble by default.
*/
@action handleFocusIn(e) {
if (this.disabled) {
// elements should not be able to be focused if disabled.
return;
}

if ((!this.disabled && !this.focusOnlyOnKey) || !this.pressed) {
this.focused = true;
if (this.args.onFocusIn) {
Expand Down
262 changes: 153 additions & 109 deletions addon/components/paper-input.hbs
Original file line number Diff line number Diff line change
@@ -1,115 +1,159 @@
{{! template-lint-disable no-action no-curly-component-invocation no-down-event-binding no-positive-tabindex }}
{{#if @label}}
<label for={{this.inputElementId}} class={{if @required "md-required"}}>{{@label}}</label>
{{/if}}

{{#if @icon}}
{{component this.iconComponent @icon}}
{{/if}}

{{#if @textarea}}
<textarea
class="md-input {{if this.isInvalid "ng-invalid"}} {{if this.isTouched "ng-dirty"}}"
id={{this.inputElementId}}
placeholder={{if this.shouldAddPlaceholder @placeholder}}
disabled={{this.disabled}}
autofocus={{this.autofocus}}
aria-describedby={{concat this.elementId "-char-count " this.elementId "-error-messages"}}
onfocus={{@onFocus}}
onblur={{action "handleBlur"}}
onkeydown={{@onKeyDown}}
onkeyup={{@onKeyUp}}
onclick={{@onClick}}
oninput={{action "handleInput"}}
{{! template-lint-disable no-down-event-binding no-positive-tabindex }}
<md-input-container
class='md-default-theme
{{~if this.hasValue " md-input-has-value"}}
{{~if this.validation.isInvalidAndTouched " md-input-invalid"}}
{{~if this.hasLeftIcon " md-icon-left"}}
{{~if this.hasRightIcon " md-icon-right"}}
{{~if this.focused " md-input-focused"}}
{{~if this.isBlock " md-block"}}
{{~if @placeholder " md-input-has-placeholder"}}
{{~if @warn " md-warn"}}
{{~if @accent " md-accent"}}
{{~if @primary " md-primary"}} {{@class}}'
disabled={{this.disabled}}
tabindex={{if this.disabled "-1" "0"}}
{{did-insert this.didInsertNode}}
{{did-update this.didUpdateNode @errors @value this.params}}
{{will-destroy this.willDestroyNode}}
...attributes
>
{{#if @label}}
<label
for={{this.inputElementId}}
class={{if @required 'md-required'}}
>{{@label}}</label>
{{/if}}

name={{@passThru.name}}
rows={{@passThru.rows}}
cols={{@passThru.cols}}
maxlength={{@passThru.maxlength}}
tabindex={{@passThru.tabindex}}
title={{@title}}
required={{@passThru.required}}
selectionEnd={{@passThru.selectionEnd}}
selectionStart={{@passThru.selectionStart}}
selectionDirection={{@passThru.selectionDirection}}
wrap={{@passThru.wrap}}
readonly={{@passThru.readonly}}
form={{@passThru.form}}
spellcheck={{@passThru.spellcheck}}></textarea>
{{else}}
<input
class="md-input {{if this.isInvalid "ng-invalid"}} {{if this.isTouched "ng-dirty"}}"
id={{this.inputElementId}}
placeholder={{if this.shouldAddPlaceholder @placeholder}}
type={{this.type}}
disabled={{this.disabled}}
autofocus={{this.autofocus}}
aria-describedby={{concat this.elementId "-char-count " this.elementId "-error-messages"}}
onfocus={{@onFocus}}
onblur={{action "handleBlur"}}
onkeydown={{@onKeyDown}}
onkeyup={{@onKeyUp}}
onclick={{@onClick}}
oninput={{action "handleInput"}}
{{#if @icon}}
{{component this.iconComponent @icon}}
{{/if}}

accept={{@passThru.accept}}
autocomplete={{@passThru.autocomplete}}
autocorrect={{@passThru.autocorrect}}
autocapitalize={{@passThru.autocapitalize}}
autosave={{@passThru.autosave}}
form={{@passThru.form}}
formaction={{@passThru.formaction}}
formenctype={{@passThru.formenctype}}
formmethod={{@passThru.formmethod}}
formnovalidate={{@passThru.formnovalidate}}
formtarget={{@passThru.formtarget}}
height={{@passThru.height}}
inputmode={{@passThru.inputmode}}
min={{@passThru.min}}
maxlength={{@passThru.maxlength}}
max={{@passThru.max}}
multiple={{@passThru.multiple}}
name={{@passThru.name}}
pattern={{@passThru.pattern}}
readonly={{@passThru.readonly}}
required={{@passThru.required}}
selectionDirection={{@passThru.selectionDirection}}
size={{@passThru.size}}
spellcheck={{@passThru.spellcheck}}
step={{@passThru.step}}
tabindex={{@passThru.tabindex}}
title={{@title}}
width={{@passThru.width}}>
{{/if}}
{{#if @textarea}}
<textarea
class='md-input
{{~if this.validation.isInvalid " ng-invalid"}}
{{~if this.validation.isTouched " ng-dirty"}}'
id={{this.inputElementId}}
placeholder={{if this.shouldAddPlaceholder @placeholder}}
disabled={{this.disabled}}
autofocus={{@autofocus}}
aria-describedby={{concat
this.elementId
'-char-count '
this.elementId
'-error-messages'
}}
onfocus={{@onFocus}}
onblur={{this.handleBlur}}
onkeydown={{@onKeyDown}}
onkeyup={{@onKeyUp}}
onclick={{@onClick}}
oninput={{this.handleInput}}
name={{@passThru.name}}
rows={{@passThru.rows}}
cols={{@passThru.cols}}
maxlength={{@passThru.maxlength}}
tabindex={{@passThru.tabindex}}
title={{@title}}
required={{@passThru.required}}
selectionEnd={{@passThru.selectionEnd}}
selectionStart={{@passThru.selectionStart}}
selectionDirection={{@passThru.selectionDirection}}
wrap={{@passThru.wrap}}
readonly={{@passThru.readonly}}
form={{@passThru.form}}
spellcheck={{@passThru.spellcheck}}
></textarea>
{{else}}
<input
class='md-input
{{~if this.validation.isInvalid " ng-invalid"}}
{{~if this.validation.isTouched " ng-dirty"}}'
id={{this.inputElementId}}
placeholder={{if this.shouldAddPlaceholder @placeholder}}
type={{this.type}}
disabled={{this.disabled}}
autofocus={{@autofocus}}
aria-describedby={{concat
this.elementId
'-char-count '
this.elementId
'-error-messages'
}}
onfocus={{@onFocus}}
onblur={{this.handleBlur}}
onkeydown={{@onKeyDown}}
onkeyup={{@onKeyUp}}
onclick={{@onClick}}
oninput={{this.handleInput}}
accept={{@passThru.accept}}
autocomplete={{@passThru.autocomplete}}
autocorrect={{@passThru.autocorrect}}
autocapitalize={{@passThru.autocapitalize}}
autosave={{@passThru.autosave}}
form={{@passThru.form}}
formaction={{@passThru.formaction}}
formenctype={{@passThru.formenctype}}
formmethod={{@passThru.formmethod}}
formnovalidate={{@passThru.formnovalidate}}
formtarget={{@passThru.formtarget}}
height={{@passThru.height}}
inputmode={{@passThru.inputmode}}
min={{@passThru.min}}
maxlength={{@passThru.maxlength}}
max={{@passThru.max}}
multiple={{@passThru.multiple}}
name={{@passThru.name}}
pattern={{@passThru.pattern}}
readonly={{@passThru.readonly}}
required={{@passThru.required}}
selectionDirection={{@passThru.selectionDirection}}
size={{@passThru.size}}
spellcheck={{@passThru.spellcheck}}
step={{@passThru.step}}
tabindex={{@passThru.tabindex}}
title={{@title}}
width={{@passThru.width}}
/>
{{/if}}

{{#unless this.hideAllMessages}}
<div class="md-errors-spacer" id={{concat this.elementId "-char-count"}}>
{{#if @maxlength}}
<div class="md-char-counter">{{this.currentLength}}/{{@maxlength}}</div>
{{/if}}
</div>
{{#if this.isInvalidAndTouched}}
<div class="md-input-messages-animation md-auto-hide" id={{concat this.elementId "-error-messages"}}>
{{#each this.validationErrorMessages as |error index|}}
<div id="error-{{this.inputElementId}}-{{index}}"
class="paper-input-error ng-enter ng-enter-active md-input-message-animation"
style="opacity: 1; margin-top: 0">
{{error.message}}
</div>
{{/each}}
{{#unless @hideAllMessages}}
<div class='md-errors-spacer' id={{concat this.elementId '-char-count'}}>
{{#if @maxlength}}
<div class='md-char-counter'>{{this.currentLength}}/{{@maxlength}}</div>
{{/if}}
</div>
{{/if}}
{{/unless}}
{{#if this.validation.isInvalidAndTouched}}
<div
class='md-input-messages-animation md-auto-hide'
id={{concat this.elementId '-error-messages'}}
>
{{#each this.validation.errorMessages as |error index|}}
<div
id='error-{{this.inputElementId}}-{{index}}'
class='paper-input-error ng-enter ng-enter-active md-input-message-animation'
style='opacity: 1; margin-top: 0'
>
{{error.message}}
</div>
{{/each}}
</div>
{{/if}}
{{/unless}}

{{yield (hash
charCount=this.currentLength
isInvalid=this.isInvalid
isTouched=this.isTouched
isInvalidAndTouched=this.isInvalidAndTouched
hasValue=this.hasValue
validationErrorMessages=this.validationErrorMessages
)}}
{{yield
(hash
charCount=this.currentLength
isInvalid=this.validation.isInvalid
isTouched=this.validation.isTouched
isInvalidAndTouched=this.validation.isInvalidAndTouched
hasValue=this.hasValue
validationErrorMessages=this.validation.errorMessages
)
}}

{{#if @iconRight}}
{{component this.iconComponent @iconRight}}
{{/if}}
{{#if @iconRight}}
{{component this.iconComponent @iconRight}}
{{/if}}
</md-input-container>
Loading
Loading