Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(code-editor): add disable scroll option for code editor #2258

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions libs/components/src/code-editor/code-editor.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ export default {
theme: 'cv-light',
code: sqlContent,
language: 'sql',
disableScroll: false,
},
};

const Template = ({ theme, language, code }) => {
const Template = ({ theme, language, code, disableScroll }) => {
return `
<div style="width: 800px; height: 100%">
<cv-code-editor language="${language}" theme="${theme}" code="${code}">
<cv-code-editor language="${language}" theme="${theme}" code="${code}" ${
disableScroll ? 'disableScroll' : ''
}>
</cv-code-editor>
</div>
`;
Expand Down
14 changes: 10 additions & 4 deletions libs/components/src/code-editor/code-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class CovalentCodeEditor extends LitElement {
* Code entered into the editor
*/
@property() code?: string;
/**
* Disable scroll bar and set the editor height based on content
*/
@property({ type: Boolean, reflect: true }) disableScroll?: boolean = false;
/**
* Options that can be set for the editor
*/
Expand Down Expand Up @@ -155,10 +159,12 @@ export class CovalentCodeEditor extends LitElement {
);
});

// Adjust the height of the editor when content changes, to avoid vertical scroll bar
this.editor?.onDidContentSizeChange(() => {
this.adjustHeight();
});
if (this.disableScroll) {
// Adjust the height of the editor when content changes, to avoid vertical scroll bar
this.editor?.onDidContentSizeChange(() => {
this.adjustHeight();
});
}

this.adjustHeight();

Expand Down
1 change: 1 addition & 0 deletions libs/components/src/notebook-cell/notebook-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class CovalentNotebookCell extends LitElement {
.language="${this.language}"
.options="${this.editorOptions}"
.theme="${this.editorTheme}"
disableScroll
></cv-code-editor>`
: html`<cv-code-snippet hideHeader .language="${this.language}"
>${this.code}</cv-code-snippet
Expand Down
Loading