Skip to content

Commit

Permalink
Merge pull request #3743 from carbon-design-system/dtp-mask-check-fix
Browse files Browse the repository at this point in the history
fix(datetimepicker): add check for mask value
  • Loading branch information
davidicus authored Mar 6, 2023
2 parents 369f44b + d86cb01 commit dd05de0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2817,4 +2817,16 @@ describe('DateTimePickerV2', () => {
expect(onApply).toHaveBeenCalledTimes(1);
});
});

it('should render without a time picker and a mask that does not include time', () => {
render(
<DateTimePicker
{...dateTimePickerProps}
i18n={i18n}
dateTimeMask="MM/DD/YYYY"
hasTimeInput={false}
/>
);
expect(screen.getByText(PRESET_VALUES[0].label)).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ const DateTimePicker = ({
const is24hours = useMemo(() => {
const [, time] = dateTimeMask.split(' ');
const hoursMask = time?.split(':')[0];
return hoursMask.includes('H');
return hoursMask ? hoursMask.includes('H') : false;
}, [dateTimeMask]);
const isSingleSelect = useMemo(() => datePickerType === 'single', [datePickerType]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { iotPrefix } = settings;
const is24hours = (dateTimeMask) => {
const [, time] = dateTimeMask.split(' ');
const hoursMask = time?.split(':')[0];
return hoursMask.includes('H');
return hoursMask ? hoursMask.includes('H') : false;
};

/** convert time from 12 hours to 24 hours, if time12hour is 24 hours format, return immediately
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/components/Header/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ $hoverBgColor: #2c2c2c;
&__menu-title[role='menuitem'][aria-expanded='true'] + &__menu {
left: auto;
right: 0;
[dir='rtl'] & {
left: 0;
right: auto;
}
}

&__menu {
Expand Down

0 comments on commit dd05de0

Please sign in to comment.