Skip to content

Commit 2bd9e6c

Browse files
committed
fix plus icon display on table
Signed-off-by: Theo Macron <theo.macron0315@gmail.com>
1 parent c6dfe28 commit 2bd9e6c

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

front/src/modules/timesStops/TimeCell.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useReducer, useRef, type ChangeEvent } from 'react';
22

3+
import { Plus } from '@osrd-project/ui-icons';
34
import type { CellContext } from '@tanstack/react-table';
45

56
import type { TimesStopsRowNew } from './types';
@@ -453,6 +454,10 @@ const TimeCell = ({
453454
dispatch({ type: 'SECTION_CLICKED', section });
454455
};
455456

457+
const handlePlaceholderClick = () => {
458+
inputRef.current?.focus();
459+
};
460+
456461
const handleFocus = (e: React.FocusEvent<HTMLInputElement>) => {
457462
const position = e.currentTarget.selectionStart || 0;
458463
const section = getSectionFromPosition(position);
@@ -479,11 +484,12 @@ const TimeCell = ({
479484
}, [state.hours, state.minutes, state.seconds, onChange]);
480485

481486
return (
482-
<div className="time-cell">
487+
<div className={`time-cell ${state.empty ? 'time-cell--empty' : ''}`}>
483488
<input
484489
ref={inputRef}
485490
value={state.empty ? 'hh:mm:ss' : formatDisplay(state)}
486491
className="time-cell__input"
492+
style={{ pointerEvents: state.empty ? 'none' : 'auto' }}
487493
onChange={(e) => e.preventDefault()}
488494
onKeyDown={handleKeyDown}
489495
onClick={handleClick}
@@ -492,7 +498,7 @@ const TimeCell = ({
492498
{...userProps}
493499
/>
494500

495-
{!state.empty && (
501+
{!state.empty ? (
496502
<div className="time-cell__display" aria-hidden="true">
497503
<span className={state.hours.includes('h') ? 'placeholder' : 'value'}>{state.hours}</span>
498504
<span className="separator">:</span>
@@ -504,9 +510,16 @@ const TimeCell = ({
504510
{state.seconds}
505511
</span>
506512
</div>
513+
) : (
514+
<div
515+
className="time-cell__placeholder"
516+
onClick={handlePlaceholderClick}
517+
role="button"
518+
tabIndex={-1}
519+
>
520+
<Plus />
521+
</div>
507522
)}
508-
509-
{state.empty && <span className="time-cell__placeholder">+</span>}
510523
</div>
511524
);
512525
};

front/src/modules/timesStops/styles/_timeCell.scss

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
display: inline-block;
44
font-size: 14px;
55
font-weight: 400;
6-
width: 84px;
7-
height: 40px;
86
line-height: 20px;
97
font-family: inherit, monospace;
8+
border-radius: 4px;
109

1110
&:hover {
1211
background-color: rgba(255, 255, 255, 0.5);
@@ -17,8 +16,9 @@
1716
position: absolute;
1817
top: 50%;
1918
left: 50%;
20-
width: 100%;
21-
height: 100%;
19+
width: 84px;
20+
height: 40px;
21+
padding-bottom: 11px;
2222
transform: translate(-50%, -50%);
2323
text-align: center;
2424
}
@@ -39,22 +39,33 @@
3939
color: transparent;
4040
caret-color: #0066cc;
4141
cursor: pointer;
42+
&:focus {
43+
outline: none;
44+
}
4245
}
4346

4447
&__placeholder {
45-
position: absolute;
46-
top: 50%;
47-
left: 50%;
48+
position: relative;
49+
width: 24px;
50+
height: 24px;
4851

49-
transform: translate(-50%, -50%);
5052
color: var(--primary40);
5153
pointer-events: auto;
5254
cursor: pointer;
5355
transition: color 0.2s;
5456
}
5557

56-
&:hover {
57-
color: var(--blackAlpha100);
58+
&:hover:not(:focus-within) {
5859
background-color: var(--primary5);
60+
.time-cell__placeholder {
61+
color: var(--primary80);
62+
}
63+
}
64+
65+
&.time-cell--empty:active {
66+
background-color: var(--primary60);
67+
.time-cell__placeholder {
68+
color: var(--white100);
69+
}
5970
}
6071
}

0 commit comments

Comments
 (0)