Skip to content

Commit

Permalink
fix(codeeditor): Code editor fix (#3842)
Browse files Browse the repository at this point in the history
* fix(codeeditor): support to copy button always enabled

* test(codeeditor): tests updates

* test(snapshot): snapshot update
  • Loading branch information
cgirani authored Feb 20, 2024
1 parent 46a619d commit eb96903
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
10 changes: 1 addition & 9 deletions packages/react/src/components/CodeEditor/CodeEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ const CodeEditor = ({

useEffect(() => {
updateEditorAttribute(disabled, editorValue);

const button = document.getElementsByClassName('iot--code-editor-copy')[0];

if (disabled) {
button.setAttribute('disabled', '');
} else if (button?.hasAttribute('disabled')) {
button.removeAttribute('disabled');
}
}, [disabled]);

/**
Expand Down Expand Up @@ -181,7 +173,7 @@ const CodeEditor = ({
<CopyButton
className={classnames(`${iotPrefix}--code-editor-copy`, {
[`${iotPrefix}--code-editor-copy--light`]: light,
[`${iotPrefix}--code-editor-copy--disabled`]: disabled,
[`${iotPrefix}--code-editor-copy--disabled-container`]: disabled,
})}
onClick={handleOnCopy}
iconDescription={mergedI18n.copyBtnDescription}
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/CodeEditor/CodeEditor.story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export const Default = () => (
<CodeEditor
language={select('Editor language', ['css', 'json', 'javascript'])}
onCopy={action('onCopy')}
initialValue="/* write your code here */"
initialValue=".className{ background: purple;}"
light={boolean('Light (light)', false)}
hasUpload={boolean('Has upload button (hasUpload)', true)}
accept={array('Accepted file types (accept)', ['.scss', '.css'], ',')}
onCodeEditorChange={action('onCodeEditorChange')}
disabled={boolean('Disabled state (disabled)', false)}
disabled={boolean('Disabled state (disabled)', true)}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('CardEditor', () => {
expect(uploadInputDisabled).toHaveAttribute('disabled');

const copyDisabled = container.querySelector(`.${iotPrefix}--code-editor-copy`);
expect(copyDisabled).toHaveAttribute('disabled');
expect(copyDisabled).not.toHaveAttribute('disabled');

rerender(
<CodeEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/C
>
<button
aria-describedby={null}
className="iot--code-editor-upload bx--btn bx--btn--md bx--btn--ghost bx--tooltip--hidden bx--btn--icon-only bx--tooltip__trigger bx--tooltip--a11y bx--btn--icon-only--top bx--tooltip--align-center"
className="iot--code-editor-upload iot--code-editor-upload--disabled bx--btn bx--btn--md bx--btn--ghost bx--btn--disabled bx--tooltip--hidden bx--btn--icon-only bx--tooltip__trigger bx--tooltip--a11y bx--btn--icon-only--top bx--tooltip--align-center"
data-testid="code-editor-upload-button"
disabled={false}
disabled={true}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -53,7 +53,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/C
]
}
className="bx--visually-hidden"
disabled={false}
disabled={true}
id="upload"
multiple={false}
name="upload"
Expand All @@ -64,7 +64,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/C
<button
aria-label={null}
aria-live="polite"
className="iot--code-editor-copy bx--copy-btn bx--copy"
className="iot--code-editor-copy iot--code-editor-copy--disabled-container bx--copy-btn bx--copy"
data-testid="code-editor-copy-button"
onAnimationEnd={[Function]}
onClick={[Function]}
Expand Down Expand Up @@ -130,7 +130,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/C
</div>
</div>
<div
className="iot--code-editor-container"
className="iot--code-editor-container iot--code-editor-container--disabled"
style={
Object {
"display": "none",
Expand Down
12 changes: 2 additions & 10 deletions packages/react/src/components/CodeEditor/_code-editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,8 @@
&-copy--light {
background-color: $ui-background;
}

&-copy--disabled {
cursor: not-allowed;
background-color: $disabled-02;
&:hover {
background-color: $disabled-02;
}
> svg {
fill: $disabled-03;
}
&-copy--disabled-container {
background-color: $active-ui;
}

&-upload.bx--btn.bx--btn--icon-only {
Expand Down

0 comments on commit eb96903

Please sign in to comment.