Skip to content
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
27 changes: 27 additions & 0 deletions addon/components/md-input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Ember from 'ember';
import MaterializeInputField from './md-input-field';
import layout from '../templates/components/md-input';

const {
get,
} = Ember;

export default MaterializeInputField.extend({
layout,
type: 'text',
Expand All @@ -9,5 +14,27 @@ export default MaterializeInputField.extend({
this._super(...arguments);
// make sure the label moves when a value is bound.
this._setupLabel();
},

actions: {
enter(...args) {
this._sendAction('onEnter', ...args);
},

keyPress(...args) {
this._sendAction('onKeyPress', ...args);
},

keyUp(...args) {
this._sendAction('onKeyUp', ...args);
}
},

_sendAction(action, ...args) {
if (typeof get(this, action) === 'function') {
get(this, action)(...args);
} else {
this.sendAction(action, ...args);
}
}
});
8 changes: 6 additions & 2 deletions addon/templates/components/md-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
disabled=disabled
autocomplete=autocomplete
autofocus=autofocus
focusIn=(action 'inputFocusIn')
step=step
min=min
max=max}}
max=max

focusIn=(action 'inputFocusIn')
enter=(action 'enter')
key-press=(action 'keyPress')
key-up=(action 'keyUp')}}
<label for="{{id}}" data-error={{_errorString}}>{{label}}</label>
21 changes: 18 additions & 3 deletions tests/dummy/app/controllers/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const {
computed,
isPresent,
later,
computed: { not }
computed: { not },
set,
} = Ember;

function asJSON(propKey) {
Expand Down Expand Up @@ -108,5 +109,19 @@ export default Controller.extend({
switchesSelectionsString: asJSON('switchesSelections'),

checkboxChoicesString: asJSON('checkboxChoices'),
checkboxSelectionsString: asJSON('checkboxSelections')
});
checkboxSelectionsString: asJSON('checkboxSelections'),

actions: {
enter() {
console.log('enter');
},

keyPress() {
console.log('key-press');
},

keyUp() {
console.log('key-up');
},
}
});
6 changes: 6 additions & 0 deletions tests/dummy/app/templates/forms.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
{{component-option optionId="pattern"}}
{{component-option optionId="validate" default="false"}}
{{component-option optionId="autocomplete"}}
{{component-option optionId="onKeyPress" default="null"}}
{{component-option optionId="onKeyUp" default="null"}}
{{component-option optionId="onEnter" default="null"}}

{{/options-panel}}
<h5>Basic Input</h5>
{{example-snippet snippet='input-basic' class='input-example'}}
<h5>Input with actions</h5>
{{example-snippet snippet='input-with-actions' class='input-example'}}
<h5>Input With Icon</h5>
{{example-snippet snippet='input-with-icon' class='input-example'}}
<h5>Typed Inputs</h5>
Expand Down
10 changes: 10 additions & 0 deletions tests/dummy/app/templates/snippets/input-with-actions.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{md-input
class="col s6"
label='Example'
placeholder="Start typing!"
value=""

onKeyPress="keyPress"
onKeyUp="keyUp"
onEnter="enter"
}}