File tree Expand file tree Collapse file tree 4 files changed +64
-32
lines changed Expand file tree Collapse file tree 4 files changed +64
-32
lines changed Original file line number Diff line number Diff line change 44<div @attributes =" AdditionalAttributes" id =" @Id" class =" @ClassString" >
55 @for ( var index = 0 ; index < Digits ; index ++ )
66 {
7- if (index < _values . Length )
7+ if (IsReadonly || IsDisabled )
88 {
9- @if (IsReadonly || IsDisabled )
10- {
11- < span class = " @ItemClassString" > @_values [index ]< / span >
12- }
13- else
14- {
15- < span class = " @ItemClassString" >
16- @{
17- var charIndex = index ;
18- }
19- < input type = " @TypeString" @bind = " @_values[charIndex]" / >
20- < / span >
21- }
9+ < span class = " @ItemClassString" > @GetValueString (index )< / span >
10+ }
11+ else
12+ {
13+ var charIndex = index ;
14+ <input type =" @TypeString" maxlength =" 1" inputmode =" @TypeModeString" class =" @ItemClassString" value =" @GetValueString(index)" @onchange =" e => OnChanged(e, charIndex)" />
2215 }
2316 }
2417</div >
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ public partial class OtpInput
3333 . Build ( ) ;
3434
3535 private string ? ItemClassString => CssBuilder . Default ( "bb-opt-item" )
36+ . AddClass ( "input-number-fix" , Type == OtpInputType . Number )
3637 . AddClass ( "disabled" , IsDisabled )
3738 . AddClass ( ValidCss )
3839 . Build ( ) ;
@@ -44,6 +45,12 @@ public partial class OtpInput
4445 _ => "text"
4546 } ;
4647
48+ private string ? TypeModeString => Type switch
49+ {
50+ OtpInputType . Number => "numeric" ,
51+ _ => "text"
52+ } ;
53+
4754 private char [ ] _values = [ ] ;
4855
4956 /// <summary>
@@ -55,4 +62,26 @@ protected override void OnParametersSet()
5562
5663 _values = Value ? . ToCharArray ( ) ?? [ ] ;
5764 }
65+
66+ private char ? GetValueString ( int index )
67+ {
68+ char ? c = _values . ElementAtOrDefault ( index ) ;
69+ if ( c == 0 )
70+ {
71+ c = null ;
72+ }
73+ return c ;
74+ }
75+
76+ private void OnChanged ( ChangeEventArgs e , int index )
77+ {
78+ if ( index < _values . Length )
79+ {
80+ var v = e . Value ? . ToString ( ) ;
81+ if ( ! string . IsNullOrEmpty ( v ) )
82+ {
83+ _values [ index ] = v [ 0 ] ;
84+ }
85+ }
86+ }
5887}
Original file line number Diff line number Diff line change 1- .bb-opt-item {
2- --bb-opt-item-padding : #{$bb-opt-item-padding } ;
3- --bb-opt-item-margin : #{$bb-opt-item-margin } ;
4- --bb-opt-font-size : #{$bb-opt-font-size } ;
5- --bb-opt-border-width : #{$bb-opt-border-width } ;
6- display : inline-block ;
7- border : var (--bb-opt-border-width ) solid var (--bs-border-color );
8- font-size : var (--bb-opt-font-size );
9- padding : var (--bb-opt-item-padding );
10- border-radius : var (--bs-border-radius );
1+ .bb-opt-input {
2+ white-space : nowrap ;
3+ overflow : hidden ;
114
12- & :not (:last-child ) {
13- margin-right : var (--bb-opt-item-margin );
14- }
5+ .bb-opt-item {
6+ --bb-opt-item-width : 66px ;
7+ --bb-opt-item-padding : #{$bb-opt-item-padding } ;
8+ --bb-opt-item-margin : #{$bb-opt-item-margin } ;
9+ --bb-opt-font-size : #{$bb-opt-font-size } ;
10+ --bb-opt-border-width : #{$bb-opt-border-width } ;
11+ display : inline-block ;
12+ border : var (--bb-opt-border-width ) solid var (--bs-border-color );
13+ font-size : var (--bb-opt-font-size );
14+ padding : var (--bb-opt-item-padding );
15+ border-radius : var (--bs-border-radius );
16+ width : var (--bb-opt-item-width );
17+ height : var (--bb-opt-item-width );
1518
16- & .disabled {
17- cursor : not-allowed ;
18- }
19+ & :not (:last-child ) {
20+ margin-right : var (--bb-opt-item-margin );
21+ }
22+
23+ & .disabled {
24+ cursor : not-allowed ;
25+ }
1926
20- > input {
27+ & [type ] {
28+ padding : 0 ;
29+ text-align : center ;
30+ }
2131 }
2232}
Original file line number Diff line number Diff line change @@ -315,7 +315,7 @@ $bb-viewer-border-radius: 50%;
315315$bb-ip-cell-max-width : 30px ;
316316
317317// OptInput
318- $bb-opt-item-padding : 0 .5 rem ;
318+ $bb-opt-item-padding : 0 .5 em ;
319319$bb-opt-item-margin : .5rem ;
320320$bb-opt-font-size : 3em ;
321321$bb-opt-border-width : 1px ;
You can’t perform that action at this time.
0 commit comments