Skip to content

Commit 7623616

Browse files
committed
[FIX] Style inner spin button
1 parent 0355a88 commit 7623616

File tree

2 files changed

+9
-72
lines changed

2 files changed

+9
-72
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
[![License](https://img.shields.io/github/license/hasan-ahani/filament-otp-input?style=flat-square)](https://github.com/hasan-ahani/filament-otp-input/blob/main/LICENSE.md)
77

88
![Preview](preview.png)
9+
10+
911
`filament-otp-input` is a package built for [Filament](https://filamentphp.com) that provides an enhanced password input form component that offers you the ability to add the following
1012
features to your password inputs:
1113

@@ -26,7 +28,6 @@ You can install the package via composer:
2628
composer require hasan-ahani/filament-otp-input
2729
```
2830

29-
3031
## Usage
3132
Inside a form schema, you can use the Otp input like this:
3233
```php
@@ -44,7 +45,8 @@ public function form(Form $form): Form
4445
}
4546
```
4647
The code above will render a otp input inside the form.
47-
![Otp input](docs/otp.png)
48+
49+
![Otp input](docs/otp.png)
4850

4951
## Number input
5052
If you want to change number input, The following code will render the inputs of use number:
@@ -64,6 +66,7 @@ public function form(Form $form): Form
6466
}
6567
```
6668
The code above will render a otp input inside the form.
69+
6770
![Otp input number](docs/otp-number.png)
6871

6972
## Number input

resources/views/components/otp-input.blade.php

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
maxlength="1"
107107
x-ref="{{$column}}"
108108
required
109-
class="fi-input block w-full border-none py-1.5 text-base text-gray-950 transition duration-75 placeholder:text-gray-400 focus:ring-0 disabled:text-gray-500 disabled:[-webkit-text-fill-color:theme(colors.gray.500)] disabled:placeholder:[-webkit-text-fill-color:theme(colors.gray.400)] dark:text-white dark:placeholder:text-gray-500 dark:disabled:text-gray-400 dark:disabled:[-webkit-text-fill-color:theme(colors.gray.400)] dark:disabled:placeholder:[-webkit-text-fill-color:theme(colors.gray.500)] sm:text-sm sm:leading-6 bg-white/0 ps-3 pe-3 text-center"
109+
class="fi-input fi-otp-input block w-full border-none py-1.5 text-base text-gray-950 transition duration-75 placeholder:text-gray-400 focus:ring-0 disabled:text-gray-500 disabled:[-webkit-text-fill-color:theme(colors.gray.500)] disabled:placeholder:[-webkit-text-fill-color:theme(colors.gray.400)] dark:text-white dark:placeholder:text-gray-500 dark:disabled:text-gray-400 dark:disabled:[-webkit-text-fill-color:theme(colors.gray.400)] dark:disabled:placeholder:[-webkit-text-fill-color:theme(colors.gray.500)] sm:text-sm sm:leading-6 bg-white/0 ps-3 pe-3 text-center"
110110
x-on:input="handleInput($event, {{$column}})"
111111
x-on:paste="handlePaste($event)"
112112
x-on:keydown.backspace="handleBackspace($event)"
@@ -116,85 +116,19 @@ class="fi-input block w-full border-none py-1.5 text-base text-gray-950 transiti
116116
@endforeach
117117

118118
</div>
119-
120-
121-
<script>
122-
function pinHandler() {
123-
return {
124-
length: 5,
125-
value: '',
126-
validation: /\d/g,
127-
updateValue() {
128-
this.value = Array.from({length: this.length}, (empty, index) => {
129-
return this.$refs[index].value || ' '
130-
}).join('')
131-
},
132-
handleInput(pin) {
133-
const value = pin.value.match(this.validation)
134-
// if the input doesn't match our needs, don't do anything
135-
if (!value || !value.length) {
136-
pin.value = ''
137-
return
138-
}
139-
140-
// TODO: We could check here if the value.length = length then check against a database
141-
142-
pin.value = value
143-
this.updateValue()
144-
this.focusNextRef(pin.getAttribute('x-ref'))
145-
},
146-
handlePaste(event) {
147-
// TODO: this validation might not be what your app requires (this one is numbers only)
148-
const text = event.clipboardData.getData('Text').match(this.validation)
149-
if (!text || !text.length) return
150-
// Get the starting input
151-
const pastedFrom = parseInt(event.target.getAttribute('x-ref'), 10)
152-
// This filters only numbers, then slices based on how many inputs remain
153-
const remainingInputs = this.length - pastedFrom
154-
const value = text.slice(0, remainingInputs).join('')
155-
// Figure out what inputs we need to update
156-
const inputsToUpdate = Array.from(Array(remainingInputs), (empty, index) => {
157-
return index + pastedFrom
158-
}).splice(0, value.length)
159-
// Update the values
160-
inputsToUpdate.forEach((ref, i) => {
161-
this.$refs[ref].value = value[i]
162-
})
163-
// Focus the last input we updated
164-
this.focusNextRef(inputsToUpdate.pop())
165-
this.updateValue()
166-
},
167-
focusNextRef(current) {
168-
const next = parseInt(current, 10) + 1
169-
if (!this.$refs[next]) {
170-
// If next doesn't exist, focus the last. A real app might auto check the database or focus a button
171-
this.$refs[parseInt(this.length, 10) - 1].focus()
172-
this.$refs[parseInt(this.length, 10) - 1].select()
173-
return
174-
}
175-
this.$refs[next].focus()
176-
this.$refs[next].select()
177-
},
178-
focusPreviousRef(current) {
179-
const previous = parseInt(current, 10) - 1
180-
this.$refs[previous] && this.$refs[previous].focus()
181-
this.$refs[previous] && this.$refs[previous].select()
182-
},
183-
}
184-
}
185-
</script>
186119
</div>
187120
</x-dynamic-component>
188121

189122
<style>
190-
input[type=number] {
123+
input.fi-otp-input[type=number] {
191124
-webkit-appearance: textfield;
192125
-moz-appearance: textfield;
193126
appearance: textfield;
194127
overflow: visible;
195128
}
196129
197-
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button {
130+
input.fi-otp-input[type=number]::-webkit-inner-spin-button,
131+
input.fi-otp-input[type=number]::-webkit-outer-spin-button {
198132
-webkit-appearance: none;
199133
-moz-appearance: none;
200134
appearance: none;

0 commit comments

Comments
 (0)