Skip to content

Commit 8bf0a00

Browse files
committed
[input] fix disabled state
1 parent 9aa34c8 commit 8bf0a00

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

demo/src/docs/components/input/icon/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import * as Vue from 'vue'
77
export class InputIcon {
88
userName: string = 'superuser'
99
password: string = 'supersecretpassword'
10+
allowEditPassword: boolean = true
1011
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
div
22
ui-form
33
ui-input(icon='user', v-model='userName', label='First Name', placeholder='Please enter your user name')
4-
ui-input(icon='lock', v-model='password', :password='true', label='Password', placeholder='Please enter password')
4+
ui-input(icon='lock', v-model='password', :password='true', label='Password', placeholder='Please enter password', :disabled='!allowEditPassword')
5+
ui-checkbox(v-model='allowEditPassword') No password

dist/vue-typed-ui.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,24 +674,32 @@ var Input = function (_InputBase2) {
674674
}, {
675675
key: 'createComponent',
676676
value: function createComponent(ch) {
677+
var attrs = {
678+
type: this.password ? 'password' : 'text',
679+
name: this.name,
680+
placeholder: this.placeholder
681+
};
682+
var css = 'ui input';
683+
if (this.disabled) {
684+
css += ' disabled';
685+
attrs['disabled'] = true;
686+
}
677687
var input = ch('input', {
678688
class: this.css,
679-
attrs: {
680-
type: this.password ? 'password' : 'text',
681-
name: this.name,
682-
placeholder: this.placeholder
683-
},
689+
attrs: attrs,
684690
on: {
685691
input: this.emiter('input'),
686692
change: this.emiter('change')
687693
}
688694
});
689-
if (!this.icon) return input;
695+
if (!this.icon) return ch('div', {
696+
class: css
697+
}, [input]);
690698
var icon = ch('i', {
691699
class: 'icon ' + this.icon
692700
});
693701
var contents = [];
694-
var css = 'ui left icon input';
702+
css = 'ui left icon input';
695703
if (this.iconPos == 'left') {
696704
contents.push(icon);
697705
contents.push(input);
@@ -3156,7 +3164,7 @@ function focus(instance, $this) {
31563164
var target = $($this.$el).find(element);
31573165
if (!target || !target.length) return;
31583166
if (!target.is('input')) {
3159-
target = target.find('> input');
3167+
target = target.find('input').first();
31603168
}
31613169
target.focus();
31623170
};

src/components/form-inputs/input/index.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { _InputBase } from './_base';
88

99
@Component()
1010
export class Input extends _InputBase {
11-
11+
1212
@Watch('value')
1313
valueChanged(val) {
1414
if (this.$el.querySelector('input') == document.activeElement)
@@ -17,34 +17,48 @@ export class Input extends _InputBase {
1717
$(this.$el).find('input').val(val)
1818
}
1919

20+
21+
2022
createComponent(ch) {
21-
23+
24+
let attrs = {
25+
type: this.password ? 'password' : 'text',
26+
name: this.name,
27+
placeholder: this.placeholder
28+
}
29+
30+
let css = 'ui input'
31+
if (this.disabled) {
32+
css += ' disabled'
33+
attrs['disabled'] = true
34+
}
35+
2236
let input = ch('input', {
2337
class: this.css,
24-
attrs: {
25-
type: this.password ? 'password' : 'text',
26-
name: this.name,
27-
placeholder: this.placeholder
28-
},
38+
attrs,
2939
on: {
3040
input: this.emiter('input'),
3141
change: this.emiter('change')
3242
}
3343
})
3444

45+
46+
3547
if (!this.icon)
36-
return input;
48+
return ch('div', {
49+
class: css
50+
}, [input])
3751

3852
let icon = ch('i', {
3953
class: 'icon ' + this.icon
4054
})
4155

4256
let contents = []
43-
let css = 'ui left icon input'
57+
css = 'ui left icon input'
4458
if (this.iconPos == 'left') {
4559
contents.push(icon)
4660
contents.push(input)
47-
} else{
61+
} else {
4862
contents.push(input)
4963
contents.push(icon)
5064
css = 'ui icon input'
@@ -55,7 +69,7 @@ export class Input extends _InputBase {
5569
}, contents)
5670

5771
}
58-
72+
5973
mounted() {
6074
// initiate value
6175
var target = $(this.$el).find('input').val(this.value)

0 commit comments

Comments
 (0)