@kigi/components 1.55.0 → 1.56.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/mbg-input-date/mbg-input-date.html +4 -4
- package/src/components/mbg-input-date/mbg-input-date.ts +22 -2
- package/src/components/mbg-input-money/mbg-input-money.html +10 -9
- package/src/components/mbg-input-money/mbg-input-money.ts +63 -38
- package/src/components/mbg-input-text/mbg-input-text.html +1 -0
- package/src/components/mbg-input-text/mbg-input-text.ts +22 -7
- package/src/components/mbg-select/mbg-select.html +3 -1
- package/src/components/mbg-select/mbg-select.ts +16 -4
- package/src/helpers/custom-key-down.ts +28 -0
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
ng-focus="$ctrl.ngFocus({ $event })"
|
|
13
13
|
ng-keyup="$ctrl.ngKeyup({ $event })"
|
|
14
14
|
ng-keypress="$ctrl.ngKeypress({ $event })"
|
|
15
|
-
ng-keydown="$ctrl.
|
|
15
|
+
ng-keydown="$ctrl.onInputKeydown($event)"
|
|
16
16
|
ui-date-mask="{{ $ctrl.format }}" />
|
|
17
17
|
<!-- with calendar -->
|
|
18
18
|
<input type="text"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
ng-focus="$ctrl.handleFocus({ $event })"
|
|
28
28
|
ng-keyup="$ctrl.ngKeyup({ $event })"
|
|
29
29
|
ng-keypress="$ctrl.ngKeypress({ $event })"
|
|
30
|
-
ng-keydown="$ctrl.
|
|
30
|
+
ng-keydown="$ctrl.onInputKeydown($event)"
|
|
31
31
|
ui-date-mask="{{ $ctrl.format }}"
|
|
32
32
|
only-month-year="$ctrl.onlyMonthYear"
|
|
33
33
|
ng-class="{'input-date':$ctrl.titleMode}"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
ng-focus="$ctrl.handleFocus({ $event })"
|
|
47
47
|
ng-keyup="$ctrl.ngKeyup({ $event })"
|
|
48
48
|
ng-keypress="$ctrl.ngKeypress({ $event })"
|
|
49
|
-
ng-keydown="$ctrl.
|
|
49
|
+
ng-keydown="$ctrl.onInputKeydown($event)"
|
|
50
50
|
ui-date-mask="{{ $ctrl.format }}"
|
|
51
51
|
on-select="$ctrl.onSelectStart()"
|
|
52
52
|
only-month-year="$ctrl.onlyMonthYear"
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
ng-focus="$ctrl.handleFocus({ $event })"
|
|
66
66
|
ng-keyup="$ctrl.ngKeyup({ $event })"
|
|
67
67
|
ng-keypress="$ctrl.ngKeypress({ $event })"
|
|
68
|
-
ng-keydown="$ctrl.
|
|
68
|
+
ng-keydown="$ctrl.onInputKeydown($event)"
|
|
69
69
|
ui-date-mask="{{ $ctrl.format }}"
|
|
70
70
|
on-select="$ctrl.onSelectEnd()"
|
|
71
71
|
only-month-year="$ctrl.onlyMonthYear"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import { focusNextElement, getNextFocusableElement } from '../../helpers/custom-key-down'
|
|
2
2
|
import template from './mbg-input-date.html'
|
|
3
|
+
import './mbg-input-date.scss'
|
|
3
4
|
declare let $
|
|
4
5
|
|
|
5
6
|
class MbgInputDateController {
|
|
@@ -17,7 +18,7 @@ class MbgInputDateController {
|
|
|
17
18
|
public betweenText: string
|
|
18
19
|
public filterDate: Function
|
|
19
20
|
public onlyMonthYear: boolean
|
|
20
|
-
|
|
21
|
+
private ngKeydown: Function
|
|
21
22
|
|
|
22
23
|
constructor(public $scope, public $element, public $attrs, public $timeout) {
|
|
23
24
|
if ($attrs.ngRequired === '') {
|
|
@@ -110,6 +111,25 @@ class MbgInputDateController {
|
|
|
110
111
|
this.ngModel.end ? this.ngModel.end.getTime() >= new Date(date).getTime() : true,
|
|
111
112
|
})
|
|
112
113
|
}
|
|
114
|
+
|
|
115
|
+
onInputKeydown(evt) {
|
|
116
|
+
if (this.ngDisabled) {
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
switch (evt.keyCode) {
|
|
121
|
+
case 9: // TAB
|
|
122
|
+
evt.preventDefault()
|
|
123
|
+
evt.stopPropagation()
|
|
124
|
+
const { focusableElements, nextIndex } = getNextFocusableElement(this.$element)
|
|
125
|
+
focusNextElement(focusableElements, nextIndex)
|
|
126
|
+
break
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (this.ngKeydown) {
|
|
130
|
+
this.ngKeydown({ $event: evt })
|
|
131
|
+
}
|
|
132
|
+
}
|
|
113
133
|
}
|
|
114
134
|
|
|
115
135
|
MbgInputDateController['$inject'] = ['$scope', '$element', '$attrs', '$timeout']
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
tabindex="-1"
|
|
3
3
|
ng-click="$ctrl.selectInput()"
|
|
4
4
|
ng-if="$ctrl.props">
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
<input type="text"
|
|
6
|
+
ng-model="$ctrl.ngModel"
|
|
7
|
+
ng-change="$ctrl.onChange()"
|
|
8
|
+
ng-required="$ctrl.ngRequired"
|
|
9
|
+
ng-disabled="$ctrl.ngDisabled"
|
|
10
|
+
ng-blur="$ctrl.ngBlur({ $event })"
|
|
11
|
+
ng-focus="$ctrl.ngFocus({ $event })"
|
|
12
|
+
ng-keydown="$ctrl.onInputKeydown($event)"
|
|
13
|
+
ui-money-mask="{{ $ctrl.props.precision }}"
|
|
14
|
+
placeholder="{{ $ctrl.props.placeholder }}" />
|
|
14
15
|
</div>
|
|
@@ -1,54 +1,79 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import { focusNextElement, getNextFocusableElement } from '../../helpers/custom-key-down'
|
|
2
2
|
import template from './mbg-input-money.html'
|
|
3
|
+
import './mbg-input-money.scss'
|
|
3
4
|
|
|
4
5
|
class MbgInputMoneyController {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
private ngChange
|
|
7
|
+
private ngModel
|
|
8
|
+
private ngRequired
|
|
9
|
+
private ngDisabled
|
|
10
|
+
private props
|
|
11
|
+
private ngKeyup: Function
|
|
12
|
+
private ngKeydown: Function
|
|
13
|
+
|
|
14
|
+
constructor(public $scope, public $element, public $attrs) {
|
|
15
|
+
if ($attrs.ngRequired === '') {
|
|
16
|
+
this.ngRequired = true
|
|
17
|
+
}
|
|
18
|
+
if ($attrs.ngDisabled === '') {
|
|
19
|
+
this.ngDisabled = true
|
|
20
|
+
}
|
|
21
|
+
this.props = {
|
|
22
|
+
placeholder: $attrs.placeholder || '',
|
|
23
|
+
prefix: $attrs.prefix || 'R$ ',
|
|
24
|
+
decimal: $attrs.decimal || ',',
|
|
25
|
+
thousands: $attrs.decimal || '.',
|
|
26
|
+
precision: this.$scope.$parent.$eval($attrs.precision) || 2,
|
|
27
|
+
allowNegative: $attrs.allowNegative ? JSON.parse($attrs.allowNegative) : true,
|
|
28
|
+
allowZero: $attrs.allowZero ? JSON.parse($attrs.allowZero) : false,
|
|
29
|
+
allowEmpty: $attrs.allowEmpty ? JSON.parse($attrs.allowEmpty) : false,
|
|
25
30
|
}
|
|
31
|
+
}
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
33
|
+
onChange() {
|
|
34
|
+
if (this.ngChange) {
|
|
35
|
+
this.ngChange({})
|
|
31
36
|
}
|
|
37
|
+
}
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
selectInput() {
|
|
40
|
+
this.$element.find('input').select()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onInputKeydown(evt) {
|
|
44
|
+
if (this.ngDisabled) {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
switch (evt.keyCode) {
|
|
49
|
+
case 9: // TAB
|
|
50
|
+
evt.preventDefault()
|
|
51
|
+
evt.stopPropagation()
|
|
52
|
+
const { focusableElements, nextIndex } = getNextFocusableElement(this.$element)
|
|
53
|
+
focusNextElement(focusableElements, nextIndex)
|
|
54
|
+
break
|
|
35
55
|
}
|
|
36
56
|
|
|
57
|
+
if (this.ngKeydown) {
|
|
58
|
+
this.ngKeydown({ $event: evt })
|
|
59
|
+
}
|
|
60
|
+
}
|
|
37
61
|
}
|
|
38
62
|
|
|
39
|
-
MbgInputMoneyController
|
|
63
|
+
MbgInputMoneyController['$inject'] = ['$scope', '$element', '$attrs']
|
|
40
64
|
|
|
41
65
|
const mbgInputMoney = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
bindings: {
|
|
67
|
+
ngModel: '=',
|
|
68
|
+
ngChange: '&?',
|
|
69
|
+
ngRequired: '=?',
|
|
70
|
+
ngDisabled: '=?',
|
|
71
|
+
ngBlur: '&?',
|
|
72
|
+
ngFocus: '&?',
|
|
73
|
+
ngKeydown: '&?',
|
|
74
|
+
},
|
|
75
|
+
template,
|
|
76
|
+
controller: MbgInputMoneyController,
|
|
52
77
|
}
|
|
53
78
|
|
|
54
79
|
export { mbgInputMoney }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import './mbg-input-text.scss'
|
|
2
|
-
import * as angular from 'angular'
|
|
3
|
-
import template from './mbg-input-text.html'
|
|
4
1
|
import { Capitalize } from '../../helpers/capitalize'
|
|
2
|
+
import { focusNextElement, getNextFocusableElement } from '../../helpers/custom-key-down'
|
|
3
|
+
import template from './mbg-input-text.html'
|
|
4
|
+
import './mbg-input-text.scss'
|
|
5
5
|
|
|
6
6
|
class MbgInputTextController {
|
|
7
7
|
private ngChange
|
|
@@ -12,6 +12,8 @@ class MbgInputTextController {
|
|
|
12
12
|
private ngKeydown
|
|
13
13
|
private ngValue
|
|
14
14
|
private capitalize
|
|
15
|
+
private focusableElements
|
|
16
|
+
private nextIndex
|
|
15
17
|
|
|
16
18
|
constructor(public $scope, public $element, public $attrs) {
|
|
17
19
|
if ($attrs.ngRequired === '') {
|
|
@@ -49,14 +51,27 @@ class MbgInputTextController {
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
onInputKeydown(evt) {
|
|
55
|
+
if (this.ngDisabled) {
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
switch (evt.keyCode) {
|
|
60
|
+
case 9: // TAB
|
|
61
|
+
evt.preventDefault()
|
|
62
|
+
evt.stopPropagation()
|
|
63
|
+
const { focusableElements, nextIndex } = getNextFocusableElement(this.$element)
|
|
64
|
+
focusNextElement(focusableElements, nextIndex)
|
|
65
|
+
break
|
|
66
|
+
}
|
|
67
|
+
|
|
54
68
|
if (this.ngKeydown) {
|
|
55
|
-
this.ngKeydown({ $event })
|
|
69
|
+
this.ngKeydown({ $event: evt })
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
72
|
}
|
|
59
|
-
|
|
73
|
+
|
|
74
|
+
MbgInputTextController['$inject'] = ['$scope', '$element', '$attrs']
|
|
60
75
|
|
|
61
76
|
const mbgInputText = {
|
|
62
77
|
bindings: {
|
|
@@ -41,10 +41,11 @@
|
|
|
41
41
|
</path>
|
|
42
42
|
</svg>
|
|
43
43
|
<i class="fa fa-caret-down mbg-icon-select"
|
|
44
|
-
ng-show="!$ctrl.ngModel && !$ctrl.isLoading"
|
|
44
|
+
ng-show="(!$ctrl.ngModel && !$ctrl.isLoading) || $ctrl.disableClearButton"
|
|
45
45
|
ng-click="$ctrl.clickArrow()"
|
|
46
46
|
aria-hidden="true"></i>
|
|
47
47
|
<i class="fa fa-times mbg-icon-select"
|
|
48
|
+
ng-if="!$ctrl.disableClearButton"
|
|
48
49
|
ng-show="$ctrl.ngModel && !$ctrl.isLoading"
|
|
49
50
|
aria-hidden="true"
|
|
50
51
|
ng-click="$ctrl.clearNgModel(true)"></i>
|
|
@@ -83,6 +84,7 @@
|
|
|
83
84
|
<input ng-model="$ctrl.inputValue"
|
|
84
85
|
ng-keydown="$ctrl.onInputKeydown($event)"
|
|
85
86
|
ng-blur="$ctrl.onInputBlur()"
|
|
87
|
+
ng-disabled="$ctrl.ngDisabled"
|
|
86
88
|
placeholder="Digite algo para pesquisar..."
|
|
87
89
|
ng-change="$ctrl.onInputChange()" />
|
|
88
90
|
</div>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Capitalize } from '../../helpers/capitalize'
|
|
2
1
|
import * as angular from 'angular'
|
|
3
|
-
import '
|
|
4
|
-
import
|
|
2
|
+
import { AbsPosition } from '../../helpers/abs-position'
|
|
3
|
+
import { Capitalize } from '../../helpers/capitalize'
|
|
5
4
|
import { MbgCookie } from '../../helpers/cookie'
|
|
5
|
+
import { focusNextElement, getNextFocusableElement } from '../../helpers/custom-key-down'
|
|
6
6
|
import { UtilUID } from '../../helpers/util-uid'
|
|
7
|
-
import
|
|
7
|
+
import template from './mbg-select.html'
|
|
8
|
+
import './mbg-select.scss'
|
|
8
9
|
|
|
9
10
|
class MbgSelectController {
|
|
10
11
|
private data: any
|
|
@@ -51,6 +52,9 @@ class MbgSelectController {
|
|
|
51
52
|
private callBackFavorite: Function
|
|
52
53
|
private favoriteModel
|
|
53
54
|
private productKitList: boolean
|
|
55
|
+
private disableClearButton: boolean
|
|
56
|
+
private focusableElements
|
|
57
|
+
private nextIndex
|
|
54
58
|
|
|
55
59
|
constructor(
|
|
56
60
|
public $scope,
|
|
@@ -65,6 +69,7 @@ class MbgSelectController {
|
|
|
65
69
|
this.fixedValue = this.ngValue || 'id'
|
|
66
70
|
this.inputValue = ''
|
|
67
71
|
this.enableAdd = this.enableAdd || false
|
|
72
|
+
this.disableClearButton = this.disableClearButton || false
|
|
68
73
|
this.observeModel()
|
|
69
74
|
this.updateInputValue()
|
|
70
75
|
this.findTransclude()
|
|
@@ -357,7 +362,10 @@ class MbgSelectController {
|
|
|
357
362
|
this.moveToDown()
|
|
358
363
|
break
|
|
359
364
|
case 9: // TAB
|
|
365
|
+
evt.preventDefault()
|
|
366
|
+
evt.stopPropagation()
|
|
360
367
|
this.setModel()
|
|
368
|
+
focusNextElement(this.focusableElements, this.nextIndex)
|
|
361
369
|
break
|
|
362
370
|
case 8: // BACKSPACE
|
|
363
371
|
this.cancelBeforePromise()
|
|
@@ -506,6 +514,9 @@ class MbgSelectController {
|
|
|
506
514
|
}
|
|
507
515
|
|
|
508
516
|
addInBody() {
|
|
517
|
+
const { focusableElements, nextIndex } = getNextFocusableElement(this.$element)
|
|
518
|
+
this.focusableElements = focusableElements
|
|
519
|
+
this.nextIndex = nextIndex
|
|
509
520
|
const body = angular.element(document).find('body')
|
|
510
521
|
const list = this.$element.find('.mbg-select-list')
|
|
511
522
|
list.attr('uid', this.uid)
|
|
@@ -750,6 +761,7 @@ const mbgSelect = {
|
|
|
750
761
|
mountValue: '&?',
|
|
751
762
|
callBackFavorite: '&?',
|
|
752
763
|
productKitList: '=?',
|
|
764
|
+
disableClearButton: '=?',
|
|
753
765
|
},
|
|
754
766
|
controller: MbgSelectController,
|
|
755
767
|
template,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as angular from 'angular'
|
|
2
|
+
|
|
3
|
+
export function getNextFocusableElement(element) {
|
|
4
|
+
var input = element.find('input')[0]
|
|
5
|
+
const focusableSelectors = 'input, select, textarea, button, a[href]'
|
|
6
|
+
const focusableElements = Array.from(document.querySelectorAll(focusableSelectors)).filter(
|
|
7
|
+
(el: any) => {
|
|
8
|
+
const notDisabled = !el.disabled && el.tabIndex !== -1
|
|
9
|
+
const isVisible = !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length)
|
|
10
|
+
const isNotButton = el.tagName.toLowerCase() !== 'button'
|
|
11
|
+
return notDisabled && isVisible && isNotButton
|
|
12
|
+
},
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const currentIndex = focusableElements.indexOf(input)
|
|
16
|
+
const nextIndex = (currentIndex + 1) % focusableElements.length
|
|
17
|
+
return { focusableElements, nextIndex }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function focusNextElement(focusableElements, nextIndex) {
|
|
21
|
+
const nextElement = focusableElements[nextIndex]
|
|
22
|
+
const nextScope = angular.element(focusableElements[nextIndex]).scope()
|
|
23
|
+
if (nextScope && nextScope.$ctrl && nextScope.$ctrl.clickInputFake) {
|
|
24
|
+
nextScope.$ctrl.clickInputFake()
|
|
25
|
+
} else {
|
|
26
|
+
nextElement.focus()
|
|
27
|
+
}
|
|
28
|
+
}
|