From 45db97bc80c3401d7f30515a1d3ee8567df283d7 Mon Sep 17 00:00:00 2001 From: Brian Hanson Date: Fri, 6 Jun 2025 10:59:47 -0500 Subject: [PATCH 1/3] Fixes #326 --- src/Field.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Field.php b/src/Field.php index 1f68bb61..c673c0d6 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1184,11 +1184,8 @@ protected function inputHtml(mixed $value, ?ElementInterface $element, $inline): ['type' => 'module'] ); - if ($ckeConfig->css) { - $view->registerCss($ckeConfig->css); - } - $value = $this->prepValueForInput($value, $element); + $inputId = Html::id('input-ckeditor-' . $id); $html = Html::textarea($this->handle, $value, [ 'id' => $id, 'class' => 'hidden', @@ -1201,10 +1198,15 @@ protected function inputHtml(mixed $value, ?ElementInterface $element, $inline): ]); } + if ($ckeConfig->css) { + $html .= Html::tag('style', "#{$inputId} { $ckeConfig->css }"); + } + return Html::tag('div', $html, [ 'class' => array_filter([ $this->showWordCount ? 'ck-with-show-word-count' : null, ]), + 'id' => $inputId, 'data' => [ 'element-id' => $element?->id, 'config' => $this->ckeConfig, From 538a5d17aec25c9910439d09e9d55d3f40f975b4 Mon Sep 17 00:00:00 2001 From: Brian Hanson Date: Mon, 16 Jun 2025 10:51:50 -0500 Subject: [PATCH 2/3] Use `registerCss` and namespace the ID --- src/Field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index c673c0d6..472273b7 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1199,7 +1199,7 @@ protected function inputHtml(mixed $value, ?ElementInterface $element, $inline): } if ($ckeConfig->css) { - $html .= Html::tag('style', "#{$inputId} { $ckeConfig->css }"); + $view->registerCss("#{$view->namespaceInputId($inputId)} { $ckeConfig->css }"); } return Html::tag('div', $html, [ From fbc09e54bc1e2295ba9861a0e68039af5a47d7f1 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 17 Feb 2026 15:43:04 -0800 Subject: [PATCH 3/3] Release note [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e1e9459..19048a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - The link modal UI now reflects Craft’s native Link fields. ([#375](https://github.com/craftcms/ckeditor/pull/375)) - Added support for drag-n-drop image uploading. ([#486](https://github.com/craftcms/ckeditor/pull/486)) - Added the “Advanced Link Fields” setting to CKEditor configs. ([#375](https://github.com/craftcms/ckeditor/pull/375)) +- Custom editor styles now get registered with a higher specificity than the default editor styles. ([#433](https://github.com/craftcms/ckeditor/pull/433)) - Added `craft\ckeditor\helpers\CkeditorConfig`. ([#363](https://github.com/craftcms/ckeditor/pull/363)) - Added `craft\ckeditor\web\assets\BaseCkeditorPackageAsset::$namespace`. ([#363](https://github.com/craftcms/ckeditor/pull/363)) - Added `craft\ckeditor\CkeConfig::$advancedLinkFields`.