Skip to content

Commit

Permalink
update input event firing (#491)
Browse files Browse the repository at this point in the history
* update input event firing

* update model check
  • Loading branch information
Nikita-Polyakov authored Dec 9, 2022
1 parent 130a589 commit f5c2d79
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 79 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@soramitsu/soramitsu-js-ui",
"version": "1.0.41",
"version": "1.0.42",
"private": false,
"publishConfig": {
"registry": "https://nexus.iroha.tech/repository/npm-soramitsu/"
Expand Down
21 changes: 15 additions & 6 deletions src/components/Checkbox/SCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</template>

<script lang="ts">
import { Component, Mixins, ModelSync, Prop } from 'vue-property-decorator'
import { Component, Mixins, Prop } from 'vue-property-decorator'
import ElCheckbox from 'element-ui/lib/checkbox'
import SizeMixin from '../../mixins/SizeMixin'
Expand All @@ -26,6 +26,10 @@ import BorderRadiusMixin from '../../mixins/BorderRadiusMixin'
components: { ElCheckbox }
})
export default class SCheckbox extends Mixins(SizeMixin, BorderRadiusMixin) {
/**
* Value of the checkbox item. Can be `string / number / boolean`
*/
@Prop() readonly value!: string | number | boolean
/**
* Label of the checkbox item
*/
Expand Down Expand Up @@ -58,11 +62,16 @@ export default class SCheckbox extends Mixins(SizeMixin, BorderRadiusMixin) {
* `false` by default
*/
@Prop({ default: false, type: Boolean }) readonly indeterminate!: boolean
/**
* Value of the checkbox item. Can be `string / number / boolean`
*/
@ModelSync('value', 'input', { type: [String, Number, Boolean] })
readonly model!: string | number | boolean
get model (): string | number | boolean {
return this.value
}
set model (value: string | number | boolean) {
if (this.value !== value) {
this.$emit('input', value)
}
}
get computedClasses (): Array<string> {
const cssClasses: Array<string> = []
Expand Down
23 changes: 16 additions & 7 deletions src/components/DatePicker/SDatePicker/SDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</template>

<script lang="ts">
import { Component, Mixins, ModelSync, Prop, Watch, Ref, Inject } from 'vue-property-decorator'
import { Component, Mixins, Prop, Watch, Ref, Inject } from 'vue-property-decorator'
import ElDatePicker from 'element-ui/lib/date-picker'
import { ElForm } from 'element-ui/types/form'
import { ElFormItem } from 'element-ui/types/form-item'
Expand All @@ -52,6 +52,11 @@ import { PickerTypes, PickerAlignment, InputTypes } from '../consts'
components: { ElDatePicker, SIcon }
})
export default class SDatePicker extends Mixins(SizeMixin, BorderRadiusMixin) {
/**
* Value of date picker component. Can be used with `v-model`.
* Can be date object / array with date objects for date range picker
*/
@Prop() readonly value!: any
/**
* Type of the date picker component. Available values:
*
Expand Down Expand Up @@ -172,12 +177,16 @@ export default class SDatePicker extends Mixins(SizeMixin, BorderRadiusMixin) {
* `true` by default
*/
@Prop({ type: Boolean, default: true }) readonly validateEvent!: boolean
/**
* Value of date picker component. Can be used with `v-model`.
* Can be date object / array with date objects for date range picker
*/
@ModelSync('value', 'input')
readonly model!: any
get model (): any {
return this.value
}
set model (value: any) {
if (JSON.stringify(value) !== JSON.stringify(this.value)) {
this.$emit('input', value)
}
}
@Watch('value')
private handlePropChange (value: any): void {
Expand Down
19 changes: 17 additions & 2 deletions src/components/Radio/SRadio/SRadio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
:disabled="disabled"
:border="border"
:name="name"
@change="handleChange"
>
<slot></slot>
</component>
</template>

<script lang="ts">
import { Component, Mixins, Prop, ModelSync } from 'vue-property-decorator'
import { Component, Mixins, Prop } from 'vue-property-decorator'
import ElRadio from 'element-ui/lib/radio'
import ElRadioButton from 'element-ui/lib/radio-button'
Expand Down Expand Up @@ -51,7 +52,17 @@ export default class SRadio extends Mixins(SizeMixin, DesignSystemInject) {
/**
* Binding value of the radio component. Can be `string` / `number` / `boolean`
*/
@ModelSync('value', 'input', { type: [String, Number, Boolean] }) readonly model!: string | number | boolean
@Prop({ type: [String, Number, Boolean] }) readonly value!: string | number | boolean
get model (): string | number | boolean {
return this.value
}
set model (value: string | number | boolean) {
if (this.value !== value) {
this.$emit('input', value)
}
}
get radioComponent () {
return this.isRadioButton ? 'el-radio-button' : 'el-radio'
Expand All @@ -67,5 +78,9 @@ export default class SRadio extends Mixins(SizeMixin, DesignSystemInject) {
}
return cssClasses
}
handleChange (value: string | number | boolean): void {
this.$emit('change', value)
}
}
</script>
14 changes: 12 additions & 2 deletions src/components/Radio/SRadioGroup/SRadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</template>

<script lang="ts">
import { Component, Mixins, Prop, ModelSync } from 'vue-property-decorator'
import { Component, Mixins, Prop } from 'vue-property-decorator'
import ElRadioGroup from 'element-ui/lib/radio-group'
import SizeMixin from '../../../mixins/SizeMixin'
Expand All @@ -25,6 +25,16 @@ export default class SRadio extends Mixins(SizeMixin) {
/**
* Binding value of the radio group. Can be `string` / `number` / `boolean`
*/
@ModelSync('value', 'input', { type: [String, Number, Boolean] }) readonly groupModel!: string | number | boolean
@Prop({ type: [String, Number, Boolean] }) readonly value!: string | number | boolean
get groupModel (): string | number | boolean {
return this.value
}
set groupModel (value: string | number | boolean) {
if (this.value !== value) {
this.$emit('input', value)
}
}
}
</script>
36 changes: 27 additions & 9 deletions src/components/Select/SSelect/SSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@focus="handleFocus"
@visible-change="handleVisibleChange"
@clear="handleClear"
@change="handleChange"
:filterable="filterable"
>
<slot name="prefix" slot="prefix"></slot>
Expand All @@ -28,7 +29,7 @@
</template>

<script lang="ts">
import { Component, Mixins, ModelSync, Prop, Watch, Ref, Inject } from 'vue-property-decorator'
import { Component, Mixins, Prop, Watch, Ref, Inject } from 'vue-property-decorator'
import ElSelect from 'element-ui/lib/select'
import { ElForm } from 'element-ui/types/form'
import { ElFormItem } from 'element-ui/types/form-item'
Expand All @@ -39,10 +40,18 @@ import DesignSystemInject from '../../DesignSystem/DesignSystemInject'
import { Autocomplete } from '../../Input/consts'
import { InputTypes } from '../consts'
type SingleSelectValue = boolean | string | number;
type MultipleSelectValue = Array<string | number>;
type SelectValue = SingleSelectValue | MultipleSelectValue;
@Component({
components: { ElSelect }
})
export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, DesignSystemInject) {
/**
* Selected value. Can be used with `v-model`
*/
@Prop({ type: [Boolean, String, Number, Array] }) readonly value!: SelectValue
/**
* Input type of the select component. Available values: `"input"`, `"select"`.
*
Expand Down Expand Up @@ -121,19 +130,24 @@ export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, Design
* `false` by default
*/
@Prop({ type: Boolean, default: false }) readonly filterable!: boolean
/**
* Selected value. Can be used with `v-model`
*/
@ModelSync('value', 'input')
readonly model!: any
get model (): SelectValue {
return this.value
}
set model (value: SelectValue) {
if (JSON.stringify(value) !== JSON.stringify(this.value)) {
this.$emit('input', value)
}
}
@Ref('select') select!: any
@Inject({ default: '', from: 'elForm' }) elForm!: ElForm
@Inject({ default: '', from: 'elFormItem' }) elFormItem!: ElFormItem
@Watch('model')
private handleValueChange (value: any): void {
private handleValueChange (): void {
this.updateInputValue()
}
Expand All @@ -148,7 +162,7 @@ export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, Design
tags.remove()
}
const input = this.select.$el.getElementsByClassName('el-input__inner')[0] as HTMLInputElement
input.value = this.model && this.model.length ? `${this.multipleTextPrefix || this.placeholder} (${this.model.length})` : ''
input.value = Array.isArray(this.model) && (this.model as MultipleSelectValue).length ? `${this.multipleTextPrefix || this.placeholder} (${this.model.length})` : ''
}
mounted (): void {
Expand Down Expand Up @@ -193,7 +207,7 @@ export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, Design
if (this.disabled) {
cssClasses.push('s-disabled')
}
if ((!this.multiple && this.model) || (this.multiple && this.model.length !== 0)) {
if ((!this.multiple && this.model) || (this.multiple && Array.isArray(this.model) && this.model.length !== 0)) {
cssClasses.push('s-has-value')
}
return cssClasses
Expand Down Expand Up @@ -233,6 +247,10 @@ export default class SSelect extends Mixins(SizeMixin, BorderRadiusMixin, Design
this.$emit('clear')
}
handleChange (value: SelectValue): void {
this.$emit('change', value)
}
public focus (): void {
this.select.focus()
}
Expand Down
22 changes: 13 additions & 9 deletions src/components/Slider/SSlider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
:range="range"
:marks="marks"
:disabled="disabled"
@input="handleInput"
@change="handleChange"
/>
</div>
</template>

<script lang="ts">
import { Vue, Component, ModelSync, Prop, Watch } from 'vue-property-decorator'
import { Vue, Component, Prop } from 'vue-property-decorator'
import ElSlider from 'element-ui/lib/slider'
import { SliderInputSize } from './consts'
Expand All @@ -35,6 +34,10 @@ import { SliderInputSize } from './consts'
components: { ElSlider }
})
export default class SSlider extends Vue {
/**
* Binding value
*/
@Prop({ default: 0, type: [Number, Array] }) readonly value!: number | number[]
/**
* Minimum value
*/
Expand Down Expand Up @@ -99,14 +102,15 @@ export default class SSlider extends Vue {
* Whether Slider is disabled
*/
@Prop({ default: false, type: Boolean }) readonly disabled!: boolean
/**
* Binding value
*/
@ModelSync('value', 'input', { default: 0, type: [Number, Array] })
readonly model!: number | number[]
handleInput (value: number): void {
this.$emit('input', value)
get model (): number | number[] {
return this.value
}
set model (value: number | number[]) {
if (JSON.stringify(value) !== JSON.stringify(this.value)) {
this.$emit('input', value)
}
}
handleChange (value: number): void {
Expand Down
15 changes: 12 additions & 3 deletions src/components/Switch/SSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</template>

<script lang="ts">
import { Component, Mixins, ModelSync, Prop, Watch } from 'vue-property-decorator'
import { Component, Mixins, Prop } from 'vue-property-decorator'
import ElSwitch from 'element-ui/lib/switch'
import DesignSystemInject from '../DesignSystem/DesignSystemInject'
Expand Down Expand Up @@ -65,8 +65,17 @@ export default class SSwitch extends Mixins(DesignSystemInject) {
/**
* Value of switch
*/
@ModelSync('value', 'input', { type: [Boolean, String, Number] })
readonly model!: boolean | string | number
@Prop({ type: [Boolean, String, Number] }) readonly value!: boolean | string | number
get model (): boolean | string | number {
return this.value
}
set model (value: boolean | string | number) {
if (this.value !== value) {
this.$emit('input', value)
}
}
handleChange (value: boolean | string | number): void {
this.$emit('change', value)
Expand Down
25 changes: 17 additions & 8 deletions src/components/Tab/STabs/STabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<script lang="ts">
import Vue from 'vue'
import { Component, Mixins, ModelSync, Prop } from 'vue-property-decorator'
import { Component, Mixins, Prop } from 'vue-property-decorator'
import ElTabs from 'element-ui/lib/tabs'
import DesignSystemInject from '../../DesignSystem/DesignSystemInject'
Expand All @@ -32,6 +32,12 @@ import { TabsType, TabsPosition } from '../consts'
components: { ElTabs }
})
export default class STabs extends Mixins(BorderRadiusMixin, DesignSystemInject) {
/**
* Name of the selected tab. Can be used with `v-model`.
*
* First value by default
*/
@Prop({ type: String }) readonly value!: string
/**
* Type of tabs. Can be `"card"`/`"border-card"`/`"rounded"` or unset.
*
Expand Down Expand Up @@ -73,13 +79,16 @@ export default class STabs extends Mixins(BorderRadiusMixin, DesignSystemInject)
* If `false` is returned or a `Promise` is returned and then is rejected, switching will be prevented
*/
@Prop({ type: Function }) readonly beforeLeave!: (activeName: string, oldActiveName: string) => (false | Promise<any>)
/**
* Name of the selected tab. Can be used with `v-model`.
*
* First value by default
*/
@ModelSync('value', 'input', { type: String })
readonly model!: string
get model (): string {
return this.value
}
set model (value: string) {
if (this.value !== value) {
this.$emit('input', value)
}
}
get computedType (): string {
// neu tabs implemented only with TabsType.ROUNDED type
Expand Down
Loading

0 comments on commit f5c2d79

Please sign in to comment.