Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit f119d6c

Browse files
[TimePicker] Properly hide separator if views not included (#1161)
1 parent 890af28 commit f119d6c

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

lib/src/TimePicker/TimePickerToolbar.tsx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@ const TimePickerToolbar: React.FC<ToolbarComponentProps> = ({
9595
>
9696
<div className={hourMinuteClassName}>
9797
{arrayIncludes(views, 'hours') && (
98-
<>
99-
<ToolbarButton
100-
variant="h2"
101-
onClick={() => setOpenView(ClockType.HOURS)}
102-
selected={openView === ClockType.HOURS}
103-
label={utils.getHourText(date, Boolean(ampm))}
104-
/>
105-
<ToolbarText variant="h2" label=":" selected={false} className={classes.separator} />
106-
</>
98+
<ToolbarButton
99+
variant="h2"
100+
onClick={() => setOpenView(ClockType.HOURS)}
101+
selected={openView === ClockType.HOURS}
102+
label={utils.getHourText(date, Boolean(ampm))}
103+
/>
104+
)}
105+
106+
{arrayIncludes(views, ['hours', 'minutes']) && (
107+
<ToolbarText variant="h2" label=":" selected={false} className={classes.separator} />
107108
)}
108109

109110
{arrayIncludes(views, 'minutes') && (
@@ -115,17 +116,17 @@ const TimePickerToolbar: React.FC<ToolbarComponentProps> = ({
115116
/>
116117
)}
117118

118-
{arrayIncludes(views, 'seconds') && (
119-
<>
120-
<ToolbarText variant="h2" label=":" selected={false} className={classes.separator} />
119+
{arrayIncludes(views, ['minutes', 'seconds']) && (
120+
<ToolbarText variant="h2" label=":" selected={false} className={classes.separator} />
121+
)}
121122

122-
<ToolbarButton
123-
variant="h2"
124-
onClick={() => setOpenView(ClockType.SECONDS)}
125-
selected={openView === ClockType.SECONDS}
126-
label={utils.getSecondText(date)}
127-
/>
128-
</>
123+
{arrayIncludes(views, 'seconds') && (
124+
<ToolbarButton
125+
variant="h2"
126+
onClick={() => setOpenView(ClockType.SECONDS)}
127+
selected={openView === ClockType.SECONDS}
128+
label={utils.getSecondText(date)}
129+
/>
129130
)}
130131
</div>
131132

lib/src/_helpers/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/** Use it instead of .includes method for IE support */
2-
export function arrayIncludes<T>(array: T[], item: T) {
3-
return array.indexOf(item) !== -1;
2+
export function arrayIncludes<T>(array: T[], itemOrItems: T | T[]) {
3+
if (Array.isArray(itemOrItems)) {
4+
return itemOrItems.every(item => array.indexOf(item) !== -1);
5+
}
6+
7+
return array.indexOf(itemOrItems) !== -1;
48
}

0 commit comments

Comments
 (0)