Skip to content

Commit

Permalink
Merge pull request #187 from MetroStar/date-picker-rerender-fix
Browse files Browse the repository at this point in the history
Fix DatePicker duplication bug
  • Loading branch information
jbouder authored Jun 26, 2024
2 parents 338d5de + 2cd0601 commit 57780ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/comet-uswds/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metrostar/comet-uswds",
"version": "2.1.1",
"version": "2.1.2",
"description": "React with TypeScript Component Library based on USWDS 3.0.",
"license": "Apache-2.0",
"main": "./dist/cjs/index.js",
Expand Down
13 changes: 9 additions & 4 deletions packages/comet-uswds/src/components/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ export const DatePicker = ({
const datePickerRef = useRef<HTMLDivElement>(null);

useLayoutEffect(() => {
const datePickerElement = datePickerRef.current as HTMLInputElement;
datePicker.on(datePickerElement);
const datePickerElement = datePickerRef.current as HTMLDivElement;
const datePickerWrapper = datePickerElement.querySelector(
'.usa-date-picker__wrapper',
) as HTMLDivElement;
if (!datePickerWrapper) datePicker.on(datePickerElement);

const externalInput = datePicker.getDatePickerContext(datePickerElement).externalInputEl;
if (onChange) {
externalInput.addEventListener('change', onChange);
Expand All @@ -63,9 +67,10 @@ export const DatePicker = ({
if (onChange) {
externalInput.removeEventListener('change', onChange);
}
datePicker.off(datePickerElement);
/* v8 ignore next */
if (datePickerWrapper) datePicker.off(datePickerElement);
};
});
}, []);

const datePickerAttributes: DatePickerAttributes = {};
if (minDate) datePickerAttributes['data-min-date'] = getDateString(minDate);
Expand Down

0 comments on commit 57780ef

Please sign in to comment.