Skip to content

Commit

Permalink
fix: avoid overriding component properties not specified in props (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker authored Oct 18, 2023
1 parent 72c71e2 commit 8fcd1e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils/createComponentWithOrderedProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default function createComponentWithOrderedProps<P extends {}, E extends
}

for (const name of names) {
orderedProps[name] = props[name];
if (props.hasOwnProperty(name)) {
orderedProps[name] = props[name];
}
}

orderedProps.ref = ref;
Expand Down
12 changes: 12 additions & 0 deletions test/DateTimePicker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ describe('DatePicker', () => {

expect(element).to.have.value(value);
});

it('should not override value set on DOM element on rerender', () => {
const { container, rerender } = render(<DateTimePicker label="Foo" />);

const element = container.querySelector('vaadin-date-time-picker');
expect(element).to.exist;
element!.value = '2020-01-01T15:00';
expect(element).to.have.value('2020-01-01T15:00');

rerender(<DateTimePicker label="Foo" />);
expect(element).to.have.value('2020-01-01T15:00');
});
});

0 comments on commit 8fcd1e8

Please sign in to comment.