Skip to content

Commit 8cc88e2

Browse files
committed
feat(textfield): pass event-listeners and attributes to input element
closes #242
1 parent 5f0527d commit 8cc88e2

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

components/textfield/README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ var vm = new Vue({
9898
|-------|------|---------|-------------|
9999
|`v-model`| String || binds textfield value |
100100
|`disabled`| [Number, String] | | binds to disabled state |
101-
|`type`|String|| input type attribute |
102-
|`name`|String|| input name attribute |
103-
|`readonly`|String|| input is readonly |
101+
|`type`|String| text | input type attribute |
104102
|`label`| String | | hint text |
105103
|`dense`| Boolean | | compresses the textfield to make it slightly smaller |
106104
|`outline`| Boolean | | whether the textfield is outlined |
@@ -120,11 +118,9 @@ var vm = new Vue({
120118
|`trailing-icon`|[String, Array, Object ] | | trailing icon _*_|
121119
|`leading-icon`| [String, Array, Object ] | | leading icon _*_ |
122120

123-
(*) icon prop usage:
124-
- use `String` for material icons
125-
- use `Array` to specify icon classList
126-
- use `{className: String, textContent: String}` for custom class and/or content
127-
- use `trailing-icon` or `leading-icon` slots for custom icon markup (svg, ...).
121+
> other attributes (`name`, `readonly`, ... ) are being passed down to the rendered input element.
122+
123+
> (*) icon prop usage: use `String` for material icons, `Array` to specify icon classList, `{className: String, textContent: String}` for custom class and/or content, or use `trailing-icon` or `leading-icon` slots for custom icon markup (svg, ...).
128124
129125
### events
130126

@@ -133,6 +129,15 @@ var vm = new Vue({
133129
|`@focus`| - |emitted on focus gained |
134130
|`@blur`| - |emitted on focus lost |
135131
|`@icon-action`| - |emitted on icon action |
132+
|`@[listener]`| - |emitted on icon action |
133+
134+
> Other bound listeners are being passsed down to the rendered input element
135+
136+
```html
137+
<mdc-textfield v-model="text" label="Hint text"
138+
@keypress.enter="handleEnterKey"/>
139+
```
140+
136141

137142
### methods
138143

components/textfield/mdc-textfield.vue

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,30 @@
1111
</i>
1212

1313
<textarea ref="input" v-if="multiline"
14+
v-on="$listeners"
15+
v-bind="$attrs"
1416
:class="inputClasses"
1517
:value="value"
1618
@input="updateValue($event.target.value)"
17-
:name="name"
1819
:minlength="minlength" :maxlength="maxlength"
1920
:placeholder="inputPlaceHolder"
20-
:readonly="readonly"
2121
:aria-label="inputPlaceHolder"
2222
:aria-controls="inputAriaControls"
23-
:rows="rows" :cols="cols" ></textarea>
23+
:rows="rows" :cols="cols"
24+
></textarea>
2425

2526
<input ref="input" v-else
27+
v-on="$listeners"
28+
v-bind="$attrs"
2629
:class="inputClasses"
2730
:value="value"
2831
@input="updateValue($event.target.value)"
2932
:type="type"
30-
:name="name"
3133
:minlength="minlength" :maxlength="maxlength"
32-
:readonly="readonly"
3334
:placeholder="inputPlaceHolder"
3435
:aria-label="inputPlaceHolder"
35-
:aria-controls="inputAriaControls" />
36+
:aria-controls="inputAriaControls"
37+
/>
3638

3739
<label ref="label" :class="labelClassesUpgraded" :for="_uid" v-if="hasLabel">
3840
{{ label }}
@@ -79,6 +81,11 @@ import {RippleBase} from '../ripple'
7981
export default {
8082
name: 'mdc-textfield',
8183
mixins: [CustomElementMixin, DispatchFocusMixin],
84+
inheritAttrs: false,
85+
model: {
86+
prop: 'value',
87+
event: 'model'
88+
},
8289
props: {
8390
value: String,
8491
type: {
@@ -89,7 +96,6 @@ export default {
8996
.indexOf(value) !== -1
9097
}
9198
},
92-
name: String,
9399
dense: Boolean,
94100
label: String,
95101
helptext: String,
@@ -99,7 +105,6 @@ export default {
99105
outline: Boolean,
100106
disabled: Boolean,
101107
required: Boolean,
102-
readonly: Boolean,
103108
valid: {type: Boolean, default: undefined},
104109
minlength: { type: [Number, String], default: undefined },
105110
maxlength: { type: [Number, String], default: undefined },
@@ -168,7 +173,7 @@ export default {
168173
},
169174
methods: {
170175
updateValue (value) {
171-
this.$emit('input', value)
176+
this.$emit('model', value)
172177
},
173178
focus () {
174179
this.$refs.input && this.$refs.input.focus()
@@ -234,12 +239,6 @@ export default {
234239
deregisterEventHandler: (evtType, handler) => {
235240
this.$refs.bottom.removeEventListener(evtType, handler)
236241
},
237-
// notifyAnimationEnd: () => {
238-
// emitCustomEvent(
239-
// this.$refs.bottom,
240-
// MDCLineRippleFoundation.strings.ANIMATION_END_EVENT,
241-
// {});
242-
// },
243242
})
244243
this.bottomLineFoundation.init()
245244
}
@@ -336,16 +335,6 @@ export default {
336335
deregisterTextFieldInteractionHandler: (evtType, handler) => {
337336
this.$refs.root.removeEventListener(evtType, handler)
338337
},
339-
// registerBottomLineEventHandler: (evtType, handler) => {
340-
// if (this.$refs.bottom) {
341-
// this.$refs.bottom.addEventListener(evtType, handler);
342-
// }
343-
// },
344-
// deregisterBottomLineEventHandler: (evtType, handler) => {
345-
// if (this.$refs.bottom) {
346-
// this.$refs.bottom.removeEventListener(evtType, handler);
347-
// }
348-
// },
349338
isFocused: () => {
350339
return document.activeElement === this.$refs.input
351340
},

0 commit comments

Comments
 (0)