Migrating from ghl-ui InputOtp to HighRise InputOtp
This guide will help you migrate from the ghl-ui InputOtp component to the new HighRise InputOtp component.
Component Implementation Changes
Import Changes
diff
- import { UIInputOtp } from '@gohighlevel/ghl-ui'
+ import { HLInputOtp } from '@platform-ui/highrise'
Basic Usage Changes
diff
- <UIInputOtp
- :fields="6"
- :disabled="false"
- placeholder="0"
- :size="'md'"
- :status="'default'"
- :separatorPosition="3"
- @onComplete="handleComplete"
- @onChange="handleChange"
- />
+ <HLInputOtp
+ id="otp-input"
+ :fields="6"
+ :disabled="false"
+ placeholder="0"
+ size="md"
+ :separator-position="3"
+ @complete="handleComplete"
+ @change="handleChange"
+ />
Form Integration Changes
diff
- <UIForm :model="formModel">
- <UIFormItem label="OTP">
- <UIInputOtp
- :fields="6"
- placeholder="0"
- :size="'md'"
- :status="'default'"
- :separatorPosition="3"
- />
- </UIFormItem>
- </UIForm>
+ <HLForm :model="formModel" :rules="rules">
+ <HLFormItem
+ label="OTP"
+ path="otp"
+ required
+ >
+ <HLInputOtp
+ id="otp-input"
+ :fields="6"
+ placeholder="0"
+ size="md"
+ :separator-position="3"
+ />
+ </HLFormItem>
+ </HLForm>
Props Changes
ghl-ui Prop | HighRise Prop | Notes |
---|---|---|
v-model | v-model:value | Changed to use value prop |
size | size | Enhanced size options |
- | separator-position | New prop introdced for specifying the position of the separator between inputs |
id | id | Required for accessibility |
Examples
Basic OTP Input
vue
<template>
<HLInputOtp id="basic-otp" :fields="6" placeholder="0" size="md" :separator-position="3" />
</template>
<script setup>
import { ref } from 'vue'
import { HLInputOtp } from '@platform-ui/highrise'
const otpValue = ref('')
</script>
OTP Input with Validation
vue
<template>
<HLForm :model="formModel" :rules="rules">
<HLFormItem label="OTP" path="otp" required>
<HLInputOtp id="otp-input" v-model:value="formModel.otp" :fields="6" placeholder="0" size="md" :separator-position="3" />
</HLFormItem>
</HLForm>
</template>
<script setup>
import { ref, computed } from 'vue'
import { HLForm, HLFormItem, HLInputOtp } from '@platform-ui/highrise'
const formModel = ref({
otp: '',
})
const validationStatus = computed(() => {
if (!formModel.value.otp) return 'error'
if (formModel.value.otp.length < 6) return 'warning'
return undefined
})
const validationMessage = computed(() => {
if (!formModel.value.otp) return 'Please enter the OTP'
if (formModel.value.otp.length < 6) return 'Please enter all digits'
return undefined
})
const rules = {
otp: [
{
required: true,
message: 'Please enter the OTP',
trigger: 'change',
},
{
len: 6,
message: 'OTP must be 6 digits',
trigger: 'change',
},
],
}
</script>
OTP Input with Custom Events
vue
<template>
<HLInputOtp
id="custom-otp"
:fields="6"
placeholder="0"
size="md"
:separator-position="3"
@complete="handleComplete"
@change="handleChange"
/>
</template>
<script setup>
import { ref } from 'vue'
import { HLInputOtp } from '@platform-ui/highrise'
const otpValue = ref('')
const handleComplete = value => {
console.log('OTP completed:', value)
}
const handleChange = value => {
console.log('OTP changed:', value)
}
</script>
Best Practices
- Always provide a unique
id
for accessibility - Use
v-model:value
for two-way binding - Implement proper form validation
- Set appropriate field count
- Use meaningful placeholders
- Add proper ARIA labels
- Handle loading states appropriately
- Use descriptive labels
- Implement proper error handling
- Consider using tooltips for additional information
- Handle disabled states properly
- Use consistent spacing and alignment
- Consider separator positions
- Handle input validation
- Consider keyboard navigation
- Implement proper error messages
Additional Notes
- The component automatically handles focus states
- Error states are managed through validation status
- Supports keyboard navigation
- Maintains consistent styling with other form components
- Handles disabled states consistently
- Integrates seamlessly with form validation
- Maintains accessibility standards
- Supports custom styling through CSS variables
- Provides clear visual feedback for all states
- Works well on both desktop and mobile devices
- Supports both controlled and uncontrolled modes
- Includes built-in validation support
- Supports custom event handling
- Handles input masking
- Supports custom separators
- Provides clear validation feedback
- Supports keyboard input
- Handles paste events