Skip to content

Commit a4c87bf

Browse files
authored
Differences in Tabindex Types Fix, V-Button Directive (#462)
* SInput, SButton, SDropdown, STooltip: Fixed differences in Tabindex types. Added V-Button Directive.
1 parent 8022d6c commit a4c87bf

File tree

11 files changed

+74
-21
lines changed

11 files changed

+74
-21
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@soramitsu/soramitsu-js-ui",
3-
"version": "1.0.35",
3+
"version": "1.0.36",
44
"private": false,
55
"publishConfig": {
66
"registry": "https://nexus.iroha.tech/repository/npm-soramitsu/"

src/components/Button/SButton/SButton.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default class SButton extends Mixins(SizeMixin, BorderRadiusMixin, Design
103103
/**
104104
* Button tabindex
105105
*/
106-
@Prop({ default: '0', type: String }) readonly tabindex!: string
106+
@Prop({ default: 0, type: [Number, String] }) readonly tabindex!: number | string
107107
/**
108108
* Placement of the tooltip. You can use any value from the `TooltipPlacement` enum.
109109
*
@@ -202,7 +202,7 @@ export default class SButton extends Mixins(SizeMixin, BorderRadiusMixin, Design
202202
}
203203
204204
mounted (): void {
205-
this.$el.setAttribute('tabindex', this.tabindex)
205+
this.$el.setAttribute('tabindex', this.tabindex.toString())
206206
this.$watch('loading', (value) => {
207207
if (!value) {
208208
return

src/components/Dropdown/SDropdown/SDropdown.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:hide-on-click="hideOnClick"
1111
:show-timeout="showTimeout"
1212
:hide-timeout="hideTimeout"
13-
:tabindex="tabindex"
13+
:tabindex="tabindexFormatted"
1414
@click="handleClick"
1515
@command="handleSelect"
1616
@visible-change="handleVisibleChange"
@@ -129,7 +129,7 @@ export default class SDropdown extends Mixins(SizeMixin, BorderRadiusMixin) {
129129
*
130130
* `0` by default
131131
*/
132-
@Prop({ type: Number, default: 0 }) readonly tabindex!: number
132+
@Prop({ type: [Number, String], default: 0 }) readonly tabindex!: number | string
133133
/**
134134
* Popper class
135135
*/
@@ -139,6 +139,10 @@ export default class SDropdown extends Mixins(SizeMixin, BorderRadiusMixin) {
139139
140140
willTooltipBeDisabled = false
141141
142+
get tabindexFormatted (): number {
143+
return +this.tabindex
144+
}
145+
142146
get computedClasses (): Array<string> {
143147
const cssClasses: Array<string> = []
144148
if (this.isStandardBorderRadius) {

src/components/Input/SInput/SInput.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
:form="form"
2929
:label="label"
3030
:accept="accept"
31-
:tabindex="tabindex"
31+
:tabindex="tabindexFormatted"
3232
:prefix-icon="prefix"
3333
:suffix-icon="suffix"
3434
:rows="rows"
@@ -154,7 +154,7 @@ export default class SInput extends Mixins(BorderRadiusMixin, DesignSystemInject
154154
/**
155155
* Input tabindex
156156
*/
157-
@Prop({ default: '', type: String }) readonly tabindex!: string
157+
@Prop({ default: 0, type: [Number, String] }) readonly tabindex!: number | string
158158
/**
159159
* Icon prefix, works only with medium input
160160
*/
@@ -214,6 +214,10 @@ export default class SInput extends Mixins(BorderRadiusMixin, DesignSystemInject
214214
return (this.type === InputType.TEXT && this.size === InputSize.BIG) || (this.type === InputType.TEXTAREA)
215215
}
216216
217+
get tabindexFormatted (): string {
218+
return this.tabindex.toString()
219+
}
220+
217221
get computedClasses (): Array<string> {
218222
const cssClasses: Array<string> = []
219223
if (this.designSystemClass) {

src/components/Tooltip/STooltip.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
:popper-class="computedPopperClass"
1515
:manual="manual"
1616
:hide-after="hideAfter"
17-
:tabindex="tabindex"
17+
:tabindex="tabindexFormatted"
1818
>
1919
<slot slot="content" name="content"></slot>
2020
<slot></slot>
@@ -116,12 +116,16 @@ export default class STooltip extends Mixins(BorderRadiusMixin, DesignSystemInje
116116
*
117117
* `0` by default
118118
*/
119-
@Prop({ default: 0, type: Number }) readonly tabindex!: number
119+
@Prop({ default: 0, type: [Number, String] }) readonly tabindex!: number | string
120120
121121
@Ref('tooltip') tooltip!: any
122122
123123
@Getter libraryTheme!: Theme
124124
125+
get tabindexFormatted (): number {
126+
return +this.tabindex
127+
}
128+
125129
get computedPopperClass (): string {
126130
const cssClasses: Array<string> = []
127131
if (this.designSystemClass) {

src/directives/button.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { DirectiveOptions } from 'vue'
2+
3+
import KeyValues from '../utils/KeyValues'
4+
5+
const onEnterKeyDown = (e: any) => {
6+
if (KeyValues.isEnter(e.key)) {
7+
e.preventDefault()
8+
e.target.click()
9+
}
10+
}
11+
12+
export const Button = {
13+
bind (el, binding, vnode) {
14+
if (binding.value || typeof binding.value === 'undefined') {
15+
const button = el as HTMLDivElement
16+
button.setAttribute('role', 'button')
17+
button.addEventListener(
18+
'keydown',
19+
onEnterKeyDown
20+
)
21+
}
22+
},
23+
unbind (el, binding, vnode) {
24+
if (binding.value || typeof binding.value === 'undefined') {
25+
const button = el as HTMLDivElement
26+
button.removeAttribute('role')
27+
button.removeEventListener(
28+
'keydown',
29+
onEnterKeyDown
30+
)
31+
}
32+
}
33+
} as DirectiveOptions

src/directives/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { Float, Integer } from './number'
2+
export { Button } from './button'

src/directives/number.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { DirectiveOptions } from 'vue'
22

33
import KeyValues from '../utils/KeyValues'
44

5-
const onDigitKeyPress = (e: any) => {
5+
const onDigitKeyDown = (e: any) => {
66
if (!KeyValues.isDigit(e.key)) {
77
e.preventDefault()
88
} else {
99
return true
1010
}
1111
}
1212

13-
const onNumberKeyPress = (e: any) => {
13+
const onNumberKeyDown = (e: any) => {
1414
if (!KeyValues.isNumber(e.key) || (!KeyValues.isDigit(e.key) && e.target.value.includes('.'))) {
1515
e.preventDefault()
1616
} else {
@@ -23,17 +23,17 @@ export const Integer = {
2323
const input = el.querySelector('input[type="text"]') as HTMLInputElement
2424
if (input) {
2525
input.addEventListener(
26-
'keypress',
27-
onDigitKeyPress
26+
'keydown',
27+
onDigitKeyDown
2828
)
2929
}
3030
},
3131
unbind (el, binding, vnode) {
3232
const input = el.querySelector('input[type="text"]') as HTMLInputElement
3333
if (input) {
3434
input.removeEventListener(
35-
'keypress',
36-
onDigitKeyPress
35+
'keydown',
36+
onDigitKeyDown
3737
)
3838
}
3939
}
@@ -44,17 +44,17 @@ export const Float = {
4444
const input = el.querySelector('input[type="text"]') as HTMLInputElement
4545
if (input) {
4646
input.addEventListener(
47-
'keypress',
48-
onNumberKeyPress
47+
'keydown',
48+
onNumberKeyDown
4949
)
5050
}
5151
},
5252
unbind (el, binding, vnode) {
5353
const input = el.querySelector('input[type="text"]') as HTMLInputElement
5454
if (input) {
5555
input.removeEventListener(
56-
'keypress',
57-
onNumberKeyPress
56+
'keydown',
57+
onNumberKeyDown
5858
)
5959
}
6060
}

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
STableColumn,
5555
STooltip
5656
} from './components'
57-
import { Float, Integer } from './directives'
57+
import { Float, Integer, Button } from './directives'
5858
import { Components } from './types/components'
5959
import { Directives } from './types/directives'
6060
import { setTheme, setDesignSystem, setLocale } from './utils'
@@ -72,6 +72,7 @@ const SoramitsuElements = {
7272
vue.use(ElementUIPlugin)
7373
vue.directive(Directives.Float, Float)
7474
vue.directive(Directives.Integer, Integer)
75+
vue.directive(Directives.Button, Button)
7576
vue.use(SApp)
7677
vue.use(SAside)
7778
vue.use(SBreadcrumb)

src/types/directives.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum Directives {
22
Float = 'Float',
3-
Integer = 'Integer'
3+
Integer = 'Integer',
4+
Button = 'Button'
45
}

src/utils/KeyValues.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default class KeyValues {
22
private static readonly digits = /[0-9]/
33
private static readonly numbers = /[0-9.]/
4+
private static readonly Enter = 'Enter'
45

56
public static isDigit (digit: string): boolean {
67
return this.digits.test(digit)
@@ -9,4 +10,8 @@ export default class KeyValues {
910
public static isNumber (number: string): boolean {
1011
return this.numbers.test(number)
1112
}
13+
14+
public static isEnter (key: string): boolean {
15+
return key === this.Enter
16+
}
1217
}

0 commit comments

Comments
 (0)