Skip to content

Commit 2d34305

Browse files
committed
feat(BFormInput): added highlight method to active a simple highlight animation for a few seconds
1 parent 470c533 commit 2d34305

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/bootstrap-vue-3/src/components/BFormInput/BFormInput.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
</template>
2626

2727
<script lang="ts">
28-
import type {InputType} from '../../types'
29-
import {computed, defineComponent, PropType} from 'vue'
28+
import {computed, defineComponent, PropType, ref} from 'vue'
3029
import {COMMON_INPUT_PROPS, useFormInput} from '../../composables'
30+
import type {InputType} from '../../types'
3131
3232
const allowedTypes = [
3333
'text',
@@ -63,6 +63,7 @@ export default defineComponent({
6363
const isRange = props.type === 'range'
6464
const isColor = props.type === 'color'
6565
return {
66+
'form-control-highlighted': isHighlighted.value,
6667
'form-range': isRange,
6768
'form-control': isColor || (!props.plaintext && !isRange),
6869
'form-control-color': isColor,
@@ -80,6 +81,15 @@ export default defineComponent({
8081
const {input, computedId, computedAriaInvalid, onInput, onChange, onBlur, focus, blur} =
8182
useFormInput(props, emit)
8283
84+
const isHighlighted = ref(false)
85+
const highlight = () => {
86+
if (isHighlighted.value === true) return
87+
isHighlighted.value = true
88+
setTimeout(() => {
89+
isHighlighted.value = false
90+
}, 2000)
91+
}
92+
8393
return {
8494
classes,
8595
localType,
@@ -91,6 +101,7 @@ export default defineComponent({
91101
onBlur,
92102
focus,
93103
blur,
104+
highlight,
94105
}
95106
},
96107
})

packages/bootstrap-vue-3/src/styles/styles.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,34 @@
3636
.dropdown-toggle.dropdown-toggle-no-caret:after {
3737
display: none !important;
3838
}
39+
3940
// No focus outline helper (use sparingly)
4041
.bv-no-focus-ring:focus {
4142
outline: none;
4243
}
44+
45+
.form-control-highlighted {
46+
border-color: $input-focus-border-color;
47+
48+
transition: box-shadow 0.3s ease-in-out;
49+
animation: form-control-highlighted-blink 1s infinite;
50+
}
51+
52+
@keyframes form-control-highlighted-blink {
53+
0% {
54+
box-shadow: 0 0 0 0 transparent;
55+
}
56+
57+
50% {
58+
@if $enable-shadows {
59+
@include box-shadow($input-box-shadow, $input-focus-box-shadow);
60+
} @else {
61+
// Avoid using mixin so we can pass custom focus shadow properly
62+
box-shadow: $input-focus-box-shadow;
63+
}
64+
}
65+
66+
100% {
67+
box-shadow: 0 0 0 0 transparent;
68+
}
69+
}

0 commit comments

Comments
 (0)