File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
src/components/FwbInput/composables Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,20 @@ import type { InputProps } from '../types'
4
4
5
5
export const useInputAttributes = ( props : InputProps ) => {
6
6
const attrs = useAttrs ( )
7
- const inputId = props ?. label && props . label !== '' ? props . label . toLowerCase ( ) . trim ( ) . replace ( / / g, '-' ) : ''
7
+ const inputId = computed ( ( ) => {
8
+ if ( ! props ?. label || props . label . trim ( ) === '' ) {
9
+ return `input-${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 9 ) } `
10
+ }
11
+ return props . label
12
+ . toLowerCase ( )
13
+ . trim ( )
14
+ . replace ( / [ ^ \w \s - ] / g, '' ) // Remove special characters
15
+ . replace ( / \s + / g, '-' ) // Replace spaces with hyphens
16
+ . replace ( / - + / g, '-' ) // Collapse multiple hyphens
17
+ } )
8
18
9
19
const inputAttributes = computed ( ( ) => {
10
- if ( inputId !== '' ) {
20
+ if ( inputId . value !== '' ) {
11
21
return {
12
22
...attrs ,
13
23
id : inputId ,
You can’t perform that action at this time.
0 commit comments