Skip to content

Commit b979338

Browse files
committed
added active class to dropdown numbers
1 parent a63fdd3 commit b979338

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/components/TimeDropdown.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useRef, MutableRefObject } from 'react'
33
import * as styles from './styles/time-dropdown'
44
import useConfig from '../hooks/config-context'
55
import { getScrollBarWidth } from '../helpers/dom'
6-
import { getTimeValue } from '../helpers/utils'
6+
import { getNormalizedTimeValue } from '../helpers/utils'
77
import { ElementRef } from '../helpers/types'
88
import { CLOCK_VALUES, MODE } from '../helpers/constants'
99
import useTimekeeperState from '../hooks/state-context'
@@ -24,7 +24,7 @@ export default function TimeDropdown({ close }: Props) {
2424
const selectedOption: ElementLiRef = useRef(null)
2525

2626
const options = CLOCK_VALUES[mode].dropdown
27-
const selected = getTimeValue(mode, time).toString()
27+
const selected = getNormalizedTimeValue(mode, time).toString()
2828

2929
function disableBodyScroll() {
3030
document.documentElement.style.paddingRight = scrollbarWidth + 'px'
@@ -86,16 +86,22 @@ export default function TimeDropdown({ close }: Props) {
8686
className="react-timekeeper__time-dropdown"
8787
>
8888
<ul css={styles.options} className="react-timekeeper__dropdown-numbers">
89-
{options.map((o) => (
90-
<li
91-
ref={(el) => (selected === o ? (selectedOption.current = el) : '')}
92-
css={styles.option(selected === o)}
93-
key={o}
94-
onClick={() => select(o)}
95-
>
96-
{o}
97-
</li>
98-
))}
89+
{options.map((o) => {
90+
const isSelected = selected === o
91+
return (
92+
<li
93+
ref={(el) => (isSelected ? (selectedOption.current = el) : '')}
94+
className={`react-timekeeper__dropdown-number ${
95+
isSelected ? 'react-timekeeper__dropdown-number--active' : ''
96+
}`}
97+
css={styles.option(isSelected)}
98+
key={o}
99+
onClick={() => select(o)}
100+
>
101+
{o}
102+
</li>
103+
)
104+
})}
99105
</ul>
100106
</div>
101107
)

src/helpers/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export function getTimeValue(mode: MODE, time: Time): number {
1010
return time[unit]
1111
}
1212

13+
export function getNormalizedTimeValue(mode: MODE, time: Time): number {
14+
const val = getTimeValue(mode, time)
15+
return mode === MODE.HOURS_12 ? val % 12 : val
16+
}
17+
1318
export function isHourMode(mode: MODE): boolean {
1419
return mode === MODE.HOURS_12 || mode === MODE.HOURS_24
1520
}

0 commit comments

Comments
 (0)