Ralfarios / antd-input-otp

An OTP Input Component based on Ant Design Component Library for React.
https://www.npmjs.com/package/antd-input-otp
19 stars 4 forks source link

How to apply styles for defaultField, activeField and filledField separately? #33

Closed anserwaseem closed 10 months ago

anserwaseem commented 10 months ago

Tell me your problem! What do you want to achieve?

How to apply styles for defaultField, activeField and filledField separately? I want to be able to set borderColor & backgroundColor in three different scenarios:

  1. Default: which can be set by passing values in inputStyle
  2. Active: how to set styles for only the active field?
  3. Filled: how to set styles for only filled fields?

@Ralfarios please help if you can

Ralfarios commented 10 months ago

Hi!

You might want to read this #15 for scenarios no.1 and 3.

For scenario no.2, you can use :where(.ant-input:focus) and :where(.ant-input-focused) for the class of the input.. like this image.

Cheers, Ralfarios.

anserwaseem commented 10 months ago

otp_Input:[value]:not([value=""]) working like a charm for scenario 3

For scenario 2: i'm using .otp_Input:focus

otp_Input:where(.ant-input:focus, otp_Input:where(.ant-input-focused gives same result as well

But the problem is that focus styles are not applied when a backspace/delete is pressed

https://github.com/Ralfarios/antd-input-otp/assets/32386713/b90f2a1b-c339-43a2-b1e8-4c33554a4c77

Ralfarios commented 10 months ago

Hello @anserwaseem !

Yup, that's because the "focused" will be overwritten with [value]..

This should work..


.input-classname:where(.ant-input:focus),
.input-classname:where(.ant-input-focused) {
  border: 2px solid royalblue !important;
  background-color: #e0f9ff;
}

.input-classname[value]:not([value=""]):not(.input-classname:where(.ant-input:focus), .input-classname:where(.ant-input-focused)) {
  border: 2px solid #3f3f3f !important;
  background-color: #f2f9ff;
}

What I did is adding more not for the case when the input is focused on the field with existed value.. Give it a try.

anserwaseem commented 10 months ago

working, thank you so much @Ralfarios