Skip to content

Commit b85f7da

Browse files
author
ugogo
committed
use className for active item
1 parent cad9800 commit b85f7da

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

playground/src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
33
import ReactInputVerificationCode from 'react-input-verification-code';
44

5-
import 'react-input-verification-code/dist/index.css';
65
import './index.css';
76

87
ReactDOM.render(

src/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ export default ({ length = 4, onChange, placeholder = '·' }: Props) => {
144144
ref={ref}
145145
role='button'
146146
tabIndex={0}
147+
className={`ReactInputVerificationCode__item ${
148+
i === activeIndex ? 'is-active' : ''
149+
}`}
147150
onFocus={onItemFocus(i)}
148-
// needed for emotion-styled
149-
isActive={i === activeIndex}
150151
>
151152
{value[i] || placeholder}
152153
</Item>

src/styles.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ export const Input = styled.input`
3131

3232
// item
3333

34-
type ItemProps = {
35-
isActive: boolean;
36-
};
37-
38-
export const Item = styled.div<ItemProps>`
34+
export const Item = styled.div`
3935
width: var(--ReactInputVerificationCode-itemWidth);
4036
height: var(--ReactInputVerificationCode-itemHeight);
4137
padding: 0;
@@ -45,8 +41,10 @@ export const Item = styled.div<ItemProps>`
4541
line-height: var(--ReactInputVerificationCode-itemHeight);
4642
text-align: center;
4743
border: 0;
48-
box-shadow: ${(props) =>
49-
`inset 0 0 0 ${props.isActive ? '2px' : '1px'}
50-
${props.isActive ? '#888' : '#ccc'}`};
44+
box-shadow: inset 0 0 0 1px #ccc;
5145
transition: box-shadow 0.2s ease-out;
46+
47+
&.is-active {
48+
box-shadow: inset 0 0 0 2px #888;
49+
}
5250
`;

0 commit comments

Comments
 (0)