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

Typescript Error—block editor custom icon #15151

Closed
ChristopherChudzicki opened this issue Oct 6, 2023 · 3 comments · Fixed by #15157
Closed

Typescript Error—block editor custom icon #15151

ChristopherChudzicki opened this issue Oct 6, 2023 · 3 comments · Fixed by #15157
Assignees
Labels
package:ui squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@ChristopherChudzicki
Copy link

ChristopherChudzicki commented Oct 6, 2023

📝 Provide detailed reproduction steps (if any)

Using v40.0.0 of ckeditor:

import type { EditorConfig } from "@ckeditor/ckeditor5-core"
import { BlockToolbar } from "@ckeditor/ckeditor5-ui"

// Not functional editor config, just showing TS error 
const config: EditorConfig = {
  plugins: [BlockToolbar],
  blockToolbar: {
    items: [],
    icon: "plus", // Typescript error
  },
}

✔️ Expected result

Assigning icon to blockToolbar should not raise an error. The docs show it off, and it works. https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/blocktoolbar.html#configuration

Before the v40.0.0 release of CKEditor 5, the block toolbar used the pilcrow icon (¶) as a handle. This was changed to braille pattern dots icon Drag indicator as a default. If you want to use a different icon, you can configure it easily, for example:

❌ Actual result

Assigning icon to blockToolbar raises a Typescript error:

Type '{ items: string[]; icon: string; }' is not assignable to type 'ToolbarConfig | undefined'.
  Object literal may only specify known properties, and 'icon' does not exist in type 'ToolbarConfig'.

❓ Possible solution

Maybe add icon?: string to the declaration at

export type ToolbarConfig = Array<ToolbarConfigItem> | {
items?: Array<ToolbarConfigItem>;
removeItems?: Array<string>;
shouldNotGroupWhenFull?: boolean;
};
, though that might allow icon in other places that it isn't actually used (not a huge problem, imo).

📃 Other details

  • 🙏 🙏🙏 Thank you for recent TS conversion 🎉
  • And for the ability to customize toolbar icon!

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@ChristopherChudzicki ChristopherChudzicki added the type:bug This issue reports a buggy (incorrect) behavior. label Oct 6, 2023
@godai78
Copy link
Contributor

godai78 commented Oct 9, 2023

Please ping me once this is done to update the user guide.

@Witoso Witoso added squad:core Issue to be handled by the Core team. package:ui labels Oct 9, 2023
@arkflpc
Copy link
Contributor

arkflpc commented Oct 9, 2023

Icons are allowed in top-level toolbar since #14646. We didn't update the config. If we hadn't had the evil Object.assign here, we could have spotted the error earlier.

@pszczesniak pszczesniak self-assigned this Oct 9, 2023
@CKEditorBot CKEditorBot added the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Oct 9, 2023
arkflpc added a commit that referenced this issue Oct 10, 2023
…icon-ts

Fix (core): Fixes typings in `ToolbarConfig` by adding optional `icon` parameter. Closes #15151.
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Oct 10, 2023
@CKEditorBot CKEditorBot added this to the iteration 68 milestone Oct 10, 2023
@arkflpc
Copy link
Contributor

arkflpc commented Oct 11, 2023

ping @godai78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:ui squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants