Unverified Commit e5bb6dad authored by Diksha Thakur's avatar Diksha Thakur Committed by GitHub

fix: Fixing EditableSection component (#508)

* Changed tag to div

* check on nativeEvent

* Fixed EditableText propagation

* Fix add new tag button

* Trying to fix tag delete click

* Fix Tag and owner onClick

* Fix clicks on Request Description

* Fix add new owner button

* code cleanup

* modified unit test cases

* Revert changes and moved children  components outside label tag

* Added unit test case
parent dfd91c27
...@@ -21,6 +21,20 @@ describe('EditableSection', () => { ...@@ -21,6 +21,20 @@ describe('EditableSection', () => {
return { wrapper, props }; return { wrapper, props };
}; };
describe('handleClick', () => {
const clickEvent = {
preventDefault: jest.fn(),
};
it('preventDefault on click', () => {
const { wrapper, props } = setup();
wrapper
.find('.editable-section-label-wrapper')
.simulate('click', clickEvent);
expect(clickEvent.preventDefault).toHaveBeenCalled();
});
});
describe('setEditMode', () => { describe('setEditMode', () => {
const { wrapper, props } = setup(); const { wrapper, props } = setup();
......
...@@ -50,6 +50,10 @@ export class EditableSection extends React.Component< ...@@ -50,6 +50,10 @@ export class EditableSection extends React.Component<
this.setState({ isEditing: !this.state.isEditing }); this.setState({ isEditing: !this.state.isEditing });
}; };
preventDefault = (event: React.MouseEvent<HTMLDivElement>) => {
event.preventDefault();
};
static convertText(str: string): string { static convertText(str: string): string {
return str return str
.split(new RegExp('[\\s+_]')) .split(new RegExp('[\\s+_]'))
...@@ -122,14 +126,17 @@ export class EditableSection extends React.Component< ...@@ -122,14 +126,17 @@ export class EditableSection extends React.Component<
return ( return (
<section className="editable-section"> <section className="editable-section">
<label className="editable-section-label"> <label className="editable-section-label">
<div className="editable-section-label-wrapper"> <div
className="editable-section-label-wrapper"
onClick={this.preventDefault}
>
<span className="section-title title-3"> <span className="section-title title-3">
{EditableSection.convertText(title)} {EditableSection.convertText(title)}
</span> </span>
{!readOnly ? this.renderButton() : this.renderReadOnlyButton()} {!readOnly ? this.renderButton() : this.renderReadOnlyButton()}
</div> </div>
<div className="editable-section-content">{childrenWithProps}</div>
</label> </label>
<div className="editable-section-content">{childrenWithProps}</div>
</section> </section>
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment