|
|
@@ -3,7 +3,7 @@
|
|
|
<view v-if="$slots.leftout" class="nut-searchbar__search-icon nut-searchbar__left-search-icon">
|
|
|
<slot name="leftout"></slot>
|
|
|
</view>
|
|
|
- <view class="nut-searchbar__search-input" :style="inputSearchbarStyle">
|
|
|
+ <view class="nut-searchbar__search-input" :style="{ ...inputSearchbarStyle, ...focusCss }">
|
|
|
<view v-if="$slots.leftin" class="nut-searchbar__search-icon nut-searchbar__iptleft-search-icon">
|
|
|
<slot name="leftin"></slot>
|
|
|
</view>
|
|
|
@@ -24,11 +24,16 @@
|
|
|
@focus="valueFocus"
|
|
|
@blur="valueBlur"
|
|
|
@confirm="handleSubmit"
|
|
|
- :style="styleSearchbar"
|
|
|
+ :style="(styleSearchbar as CSSProperties)"
|
|
|
/>
|
|
|
</form>
|
|
|
- <view @click="handleClear" class="nut-searchbar__input-clear" v-if="clearable" v-show="modelValue.length > 0">
|
|
|
- <nut-icon name="circle-close" size="12" color="#555"></nut-icon>
|
|
|
+ <view
|
|
|
+ @click="handleClear"
|
|
|
+ class="nut-searchbar__input-clear"
|
|
|
+ v-if="clearable"
|
|
|
+ v-show="(modelValue as string).length > 0"
|
|
|
+ >
|
|
|
+ <nut-icon :name="clearIcon" size="12" color="#555"></nut-icon>
|
|
|
</view>
|
|
|
</view>
|
|
|
<view v-if="$slots.rightin" class="nut-searchbar__search-icon nut-searchbar__iptright-sarch-icon">
|
|
|
@@ -42,13 +47,13 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import { toRefs, reactive, computed, ref, onMounted, PropType } from 'vue';
|
|
|
+import { toRefs, reactive, computed, ref, onMounted, PropType, Ref, CSSProperties } from 'vue';
|
|
|
import { createComponent } from '@/packages/utils/create';
|
|
|
const { create, translate } = createComponent('searchbar');
|
|
|
-interface Events {
|
|
|
- eventName: 'change' | 'focus' | 'blur' | 'clear' | 'update:modelValue';
|
|
|
- params: (string | number | Event)[];
|
|
|
-}
|
|
|
+// interface Events {
|
|
|
+// eventName: 'change' | 'focus' | 'blur' | 'clear' | 'update:modelValue';
|
|
|
+// params: (string | number | Event)[];
|
|
|
+// }
|
|
|
export type confirmTextType = 'send' | 'search' | 'next' | 'go' | 'done';
|
|
|
|
|
|
export default create({
|
|
|
@@ -73,6 +78,10 @@ export default create({
|
|
|
type: Boolean,
|
|
|
default: true
|
|
|
},
|
|
|
+ clearIcon: {
|
|
|
+ type: String,
|
|
|
+ default: 'circle-close'
|
|
|
+ },
|
|
|
background: {
|
|
|
type: String,
|
|
|
default: ''
|
|
|
@@ -89,6 +98,11 @@ export default create({
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
},
|
|
|
+ focusStyle: {
|
|
|
+ type: Object,
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
|
+ default: () => {}
|
|
|
+ },
|
|
|
disabled: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
@@ -142,10 +156,12 @@ export default create({
|
|
|
emit('change', val, event);
|
|
|
};
|
|
|
|
|
|
+ const focusCss = ref({});
|
|
|
const valueFocus = (event: Event) => {
|
|
|
const input = event.target as HTMLInputElement;
|
|
|
let value = input.value;
|
|
|
state.active = true;
|
|
|
+ focusCss.value = props.focusStyle;
|
|
|
emit('focus', value, event);
|
|
|
};
|
|
|
|
|
|
@@ -159,6 +175,7 @@ export default create({
|
|
|
if (props.maxLength && value.length > Number(props.maxLength)) {
|
|
|
value = value.slice(0, Number(props.maxLength));
|
|
|
}
|
|
|
+ focusCss.value = {};
|
|
|
emit('blur', value, event);
|
|
|
};
|
|
|
|
|
|
@@ -184,15 +201,17 @@ export default create({
|
|
|
emit('click-right-icon', props.modelValue, event);
|
|
|
};
|
|
|
|
|
|
- const styleSearchbar: any = computed(() => {
|
|
|
+ const styleSearchbar = computed(() => {
|
|
|
return {
|
|
|
- 'text-align': props.inputAlign
|
|
|
+ style: {
|
|
|
+ textAlign: props.inputAlign
|
|
|
+ }
|
|
|
};
|
|
|
});
|
|
|
- const inputsearch: any = ref(null);
|
|
|
+ const inputsearch: Ref<HTMLElement | null> = ref(null);
|
|
|
onMounted(() => {
|
|
|
if (props.autofocus) {
|
|
|
- inputsearch.value.focus();
|
|
|
+ (inputsearch.value as HTMLElement).focus();
|
|
|
}
|
|
|
});
|
|
|
return {
|
|
|
@@ -205,6 +224,7 @@ export default create({
|
|
|
handleSubmit,
|
|
|
searchbarStyle,
|
|
|
inputSearchbarStyle,
|
|
|
+ focusCss,
|
|
|
translate,
|
|
|
clickInput,
|
|
|
leftIconClick,
|