Skip to content

Commit 9766439

Browse files
pdanpdanrstoenescu
authored andcommitted
QInlineEdit: focus input by .q-input-target, prevent ENTER propagation on textarea (quasarframework#2456)
* QInlineEdit: focus input by .q-input-target, prevent ENTER propagation on textarea * Rename QInlineEdit to QPopupEdit
1 parent 5ea3646 commit 9766439

File tree

6 files changed

+38
-17
lines changed

6 files changed

+38
-17
lines changed

dev/components/components/data-table.vue

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<q-radio v-model="separator" val="none" label="None" />
1616
</div>
1717

18-
<h2>Inline editing</h2>
18+
<h2>Popup editing</h2>
1919
<p class="caption">Click on Dessert or Calories cells.</p>
2020
<q-table
2121
:data="data"
@@ -27,22 +27,36 @@
2727
<q-tr slot="body" slot-scope="props" :props="props">
2828
<q-td key="desc" :props="props">
2929
{{ props.row.name }}
30-
<q-inline-edit v-model="props.row.name">
30+
<q-popup-edit v-model="props.row.name">
3131
<q-field count>
3232
<q-input v-model="props.row.name" />
3333
</q-field>
34-
</q-inline-edit>
34+
</q-popup-edit>
3535
</q-td>
3636
<q-td key="calories" :props="props">
3737
{{ props.row.calories }}
38-
<q-inline-edit v-model="props.row.calories" title="Update calories" buttons>
38+
<q-popup-edit v-model="props.row.calories" title="Update calories" buttons>
3939
<q-field count>
4040
<q-input type="number" v-model="props.row.calories" />
4141
</q-field>
42-
</q-inline-edit>
42+
</q-popup-edit>
43+
</q-td>
44+
<q-td key="fat" :props="props">
45+
<div class="text-pre-wrap">{{ props.row.fat }}</div>
46+
<q-popup-edit v-model="props.row.fat">
47+
<q-field count>
48+
<q-input type="textarea" v-model="props.row.fat" />
49+
</q-field>
50+
</q-popup-edit>
51+
</q-td>
52+
<q-td key="carbs" :props="props">
53+
{{ props.row.carbs }}
54+
<q-popup-edit v-model="props.row.carbs" title="Update carbs" buttons persistent>
55+
<q-field count helper="Use buttons to close">
56+
<q-input type="number" v-model="props.row.carbs" />
57+
</q-field>
58+
</q-popup-edit>
4359
</q-td>
44-
<q-td key="fat" :props="props">{{ props.row.fat }}</q-td>
45-
<q-td key="carbs" :props="props">{{ props.row.carbs }}</q-td>
4660
<q-td key="protein" :props="props">{{ props.row.protein }}</q-td>
4761
<q-td key="sodium" :props="props">{{ props.row.sodium }}</q-td>
4862
<q-td key="calcium" :props="props">{{ props.row.calcium }}</q-td>
@@ -682,4 +696,6 @@ export default {
682696
<style lang="stylus">
683697
.q-table + .q-table
684698
margin-top 25px
699+
.text-pre-wrap
700+
white-space pre-wrap
685701
</style>

src/components.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export * from './components/fab/index.js'
2020
export * from './components/field/index.js'
2121
export * from './components/icon/index.js'
2222
export * from './components/infinite-scroll/index.js'
23-
export * from './components/inline-edit/index.js'
2423
export * from './components/inner-loading/index.js'
2524
export * from './components/input/index.js'
2625
export * from './components/input-frame/index.js'
@@ -35,6 +34,7 @@ export * from './components/option-group/index.js'
3534
export * from './components/pagination/index.js'
3635
export * from './components/parallax/index.js'
3736
export * from './components/popover/index.js'
37+
export * from './components/popup-edit/index.js'
3838
export * from './components/progress/index.js'
3939
export * from './components/pull-to-refresh/index.js'
4040
export * from './components/radio/index.js'

src/components/inline-edit/index.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import clone from '../../utils/clone.js'
44
import { getEventKey } from '../../utils/event.js'
55

66
export default {
7-
name: 'QInlineEdit',
7+
name: 'QPopupEdit',
88
props: {
99
value: {},
1010
persistent: Boolean,
@@ -96,7 +96,7 @@ export default {
9696
},
9797
on: {
9898
show: () => {
99-
const input = this.$el.querySelector('input')
99+
const input = this.$el.querySelector('.q-input-target, input')
100100
input && input.focus()
101101
this.$emit('show')
102102
this.initialValue = clone(this.value)

src/components/popup-edit/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import QPopupEdit from './QPopupEdit.js'
2+
3+
export {
4+
QPopupEdit
5+
}

src/mixins/input.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ export default {
6868
})
6969
},
7070
__onKeydown (e) {
71-
if (this.type !== 'textarea' && e.keyCode === 13) {
72-
this.__emit()
71+
if (e.keyCode === 13) {
72+
if (this.type === 'textarea') {
73+
e.stopPropagation()
74+
}
75+
else {
76+
this.__emit()
77+
}
7378
}
7479
this.$emit('keydown', e)
7580
},

0 commit comments

Comments
 (0)