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

Set Tinymce editor form min-height #2691

Merged
merged 1 commit into from
Jan 16, 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
9 changes: 8 additions & 1 deletion app/javascript/alchemy_admin/components/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,19 @@ class Tinymce extends AlchemyHTMLElement {
}
})

return {
const config = {
...Alchemy.TinymceDefaults,
...customConfig,
language: currentLocale(),
selector: `#${this.editorId}`
}

// Tinymce has a height of 400px by default
// if the element has a min_height set, we use this value for the height as well
// so we do not need to set both values in the element configuration
config.height = config.min_height

return config
}

get editorId() {
Expand Down
1 change: 0 additions & 1 deletion lib/alchemy/tinymce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module Tinymce
width: "auto",
resize: true,
min_height: 250,
height: 250,
menubar: false,
statusbar: true,
toolbar: [
Expand Down
39 changes: 39 additions & 0 deletions spec/javascript/alchemy_admin/components/tinymce.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ describe("alchemy-tinymce", () => {
<textarea id="${textareaId}"></textarea>
</alchemy-tinymce>
`
// The tinymce configuration is set in the global Alchemy object
// because we translate the configuration from the Rails backend
// into the JS world.
Alchemy.TinymceDefaults = {
skin: "alchemy",
content_css: "/assets/tinymce/skins/content/alchemy/content.min.css",
icons: "remixicons",
width: "auto",
resize: true,
min_height: 250,
menubar: false,
statusbar: true,
toolbar: [
"bold italic underline | strikethrough subscript superscript | numlist bullist indent outdent | removeformat | fullscreen",
"pastetext charmap hr | undo redo | alchemy_link unlink anchor | code"
],
fix_list_elements: true,
convert_urls: false,
entity_encoding: "raw",
paste_as_text: true,
element_format: "html",
branding: false
}
component = renderComponent("alchemy-tinymce", html)
})

Expand All @@ -71,6 +94,22 @@ describe("alchemy-tinymce", () => {
it("should set the selector to textarea id", () => {
expect(component.configuration.selector).toEqual("#tinymce-textarea")
})

it("sets height to min_height from defaults", () => {
expect(component.configuration.height).toEqual(250)
})

describe("if min-height is set on component", () => {
it("uses that value for height", () => {
const html = `
<alchemy-tinymce toolbar="bold italic" foo-bar="bar | foo" min-height="400">
<textarea id="${textareaId}"></textarea>
</alchemy-tinymce>
`
component = renderComponent("alchemy-tinymce", html)
expect(component.configuration.height).toEqual(400)
})
})
})

describe("minHeight", () => {
Expand Down
Loading