chore: optional chaining (#8283)

This commit is contained in:
neverland 2021-03-05 11:05:27 +08:00 committed by GitHub
parent 391ccd4240
commit 09e1eb5a0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 47 deletions

View File

@ -145,10 +145,9 @@ export default createComponent({
}); });
// hide bottom field when use search && detail get focused // hide bottom field when use search && detail get focused
const hideBottomFields = computed(() => { const hideBottomFields = computed(
const { searchResult } = props; () => props.searchResult?.length && state.detailFocused
return searchResult && searchResult.length && state.detailFocused; );
});
const assignAreaValues = () => { const assignAreaValues = () => {
if (areaRef.value) { if (areaRef.value) {

View File

@ -39,8 +39,8 @@ export default createComponent({
return; return;
} }
const currentName = computed(() => props.name ?? index.value); const name = computed(() => props.name ?? index.value);
const expanded = computed(() => parent.isExpanded(currentName.value)); const expanded = computed(() => parent.isExpanded(name.value));
const show = ref(expanded.value); const show = ref(expanded.value);
const lazyRender = useLazyRender(show); const lazyRender = useLazyRender(show);
@ -86,8 +86,8 @@ export default createComponent({
}); });
}); });
const toggle = (value = !expanded.value) => { const toggle = (newValue = !expanded.value) => {
parent.toggle(currentName.value, value); parent.toggle(name.value, newValue);
}; };
const onClickTitle = () => { const onClickTitle = () => {

View File

@ -283,7 +283,7 @@ export default createComponent({
value = props.formatter(value); value = props.formatter(value);
} }
if (inputRef.value && value !== inputRef.value.value) { if (inputRef.value && inputRef.value.value !== value) {
inputRef.value.value = value; inputRef.value.value = value;
} }
@ -299,17 +299,8 @@ export default createComponent({
} }
}; };
const focus = () => { const blur = () => inputRef.value?.blur();
if (inputRef.value) { const focus = () => inputRef.value?.focus();
inputRef.value.focus();
}
};
const blur = () => {
if (inputRef.value) {
inputRef.value.blur();
}
};
const onFocus = (event: Event) => { const onFocus = (event: Event) => {
state.focused = true; state.focused = true;

View File

@ -29,7 +29,7 @@ import ImagePreviewItem from './ImagePreviewItem';
const [createComponent, bem] = createNamespace('image-preview'); const [createComponent, bem] = createNamespace('image-preview');
export type ImagePreviewScaleEventParams = { export type ScaleEventParams = {
scale: number; scale: number;
index: number; index: number;
}; };
@ -110,8 +110,7 @@ export default createComponent({
} }
}; };
const emitScale = (args: ImagePreviewScaleEventParams) => const emitScale = (args: ScaleEventParams) => emit('scale', args);
emit('scale', args);
const updateShow = (show: boolean) => emit('update:show', show); const updateShow = (show: boolean) => emit('update:show', show);
@ -191,11 +190,8 @@ export default createComponent({
const onClosed = () => emit('closed'); const onClosed = () => emit('closed');
const swipeTo = (index: number, options?: SwipeToOptions) => { const swipeTo = (index: number, options?: SwipeToOptions) =>
if (swipeRef.value) { swipeRef.value?.swipeTo(index, options);
swipeRef.value.swipeTo(index, options);
}
};
useExpose({ swipeTo }); useExpose({ swipeTo });
@ -205,9 +201,7 @@ export default createComponent({
watch( watch(
() => props.startPosition, () => props.startPosition,
(value) => { (value) => setActive(+value)
setActive(+value);
}
); );
watch( watch(

View File

@ -92,17 +92,8 @@ export default createComponent({
} }
}; };
const focus = () => { const blur = () => filedRef.value?.blur();
if (filedRef.value) { const focus = () => filedRef.value?.focus();
filedRef.value.focus();
}
};
const blur = () => {
if (filedRef.value) {
filedRef.value.blur();
}
};
const fieldPropNames = [ const fieldPropNames = [
'leftIcon', 'leftIcon',

View File

@ -208,8 +208,8 @@ export default createComponent({
const onFocus = (event: Event) => { const onFocus = (event: Event) => {
// readonly not work in lagacy mobile safari // readonly not work in lagacy mobile safari
if (props.disableInput && inputRef.value) { if (props.disableInput) {
inputRef.value.blur(); inputRef.value?.blur();
} else { } else {
emit('focus', event); emit('focus', event);
} }

View File

@ -388,9 +388,11 @@ export default createComponent({
const renderDot = (_: number, index: number) => { const renderDot = (_: number, index: number) => {
const active = index === activeIndicator.value; const active = index === activeIndicator.value;
const style: CSSProperties = { const style = active
backgroundColor: active ? props.indicatorColor : undefined, ? {
}; backgroundColor: props.indicatorColor,
}
: undefined;
return <i style={style} class={bem('indicator', { active })} />; return <i style={style} class={bem('indicator', { active })} />;
}; };