Skip to content

Commit

Permalink
[#646][3.0] Select 컴포넌트 change 이벤트가 안되는 현상 수정 (#858)
Browse files Browse the repository at this point in the history
Co-authored-by: byeongwan <byeongwan@ex-em.com>
  • Loading branch information
byeongwan-kim and byeongwan authored Aug 9, 2021
1 parent 2de5b76 commit 312d9ca
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/views/select/api/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

| 이름 | 파라미터 | 설명 |
| ---- | ------- | ---- |
| change | newValue, event | <셀렉트> 내 v-model 변화 이벤트 감지 |
| change | newValue | <셀렉트> 내 v-model 변화 이벤트 감지 |

>### 참고
-
5 changes: 2 additions & 3 deletions docs/views/select/example/Default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
first selectbox value : {{ selectVal1 }}
</div>
<div class="description">
change val : {{ selectEventVal.val }} / change e : {{ selectEventVal.e }}
change val : {{ selectEventVal.val }}
</div>
</div>
<div class="case">
Expand Down Expand Up @@ -142,9 +142,8 @@ export default {
value: `value${count}`,
});
};
const changeSelect1 = (val, e) => {
const changeSelect1 = (val) => {
selectEventVal.val = val;
selectEventVal.e = e;
};
const selectVal3 = ref('value1');
Expand Down
10 changes: 10 additions & 0 deletions docs/views/select/example/Multiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
:items="items1"
placeholder="Please select values."
multiple
@change="changeEvent"
/>
<div class="description">
first selectbox value : {{ selectVal1 }}
</div>
<div class="description">
change val : {{ changeVal }}
</div>
</div>
<div class="case">
<p class="case-title">Multiple Clearable Select</p>
Expand Down Expand Up @@ -104,10 +108,16 @@ export default {
value: 'value7',
},
]);
const changeVal = ref();
const changeEvent = (val) => {
changeVal.value = val;
};
return {
selectVal1,
items1,
changeVal,
changeEvent,
};
},
};
Expand Down
3 changes: 1 addition & 2 deletions src/components/select/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
readonly
:placeholder="computedPlaceholder"
:disabled="disabled"
@change="changeMv"
@click="clickSelectInput"
/>
</template>
Expand Down Expand Up @@ -240,7 +239,7 @@ export default {
changeDropboxPosition,
clickItem,
selectedItemClass,
} = useDropdown({ mv });
} = useDropdown({ mv, changeMv });
return {
mv,
Expand Down
24 changes: 13 additions & 11 deletions src/components/select/uses.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,27 @@ export const useModel = () => {
}
};

/**
* 해당 컴포넌트의 v-model값이 변경(change)되는 이벤트
*/
const changeMv = async () => {
await nextTick();
emit('change', mv.value);
};

/**
* multiple 모드인 경우 선택된 value를 mv에서 삭제하는 로직
* @param val - tagWrapper에서 [x]클릭된 목록의 value
*/
const removeMv = (val) => {
const removeMv = async (val) => {
if (!props.disabled) {
const idx = mv.value.indexOf(val);
mv.value.splice(idx, 1);
mv.value = [...mv.value];
await changeMv();
}
};

/**
* 해당 컴포넌트의 v-model값이 변경(change)되는 이벤트
* @param e
*/
const changeMv = async (e) => {
await nextTick();
emit('change', mv.value, e);
};

return {
mv,
selectedModel,
Expand All @@ -102,7 +102,7 @@ export const useModel = () => {

export const useDropdown = (param) => {
const { props } = getCurrentInstance();
const { mv } = param;
const { mv, changeMv } = param;

const isDropbox = ref(false);
const filterTextRef = ref(props.filterText);
Expand Down Expand Up @@ -218,6 +218,7 @@ export const useDropdown = (param) => {
}
mv.value = val;
isDropbox.value = false;
changeMv();
};
const multipleClickItem = (val) => {
if (props.filterable) {
Expand All @@ -229,6 +230,7 @@ export const useDropdown = (param) => {
const idx = mv.value.indexOf(val);
mv.value.splice(idx, 1);
}
changeMv();
};
const clickItem = !props.multiple ? singleClickItem : multipleClickItem;

Expand Down

0 comments on commit 312d9ca

Please sign in to comment.