Skip to content

Commit

Permalink
Fixes bug not being able to omit heading1
Browse files Browse the repository at this point in the history
Build

Removed build in package json
  • Loading branch information
mortmoe committed Jul 19, 2024
1 parent 7a5a7f2 commit 609135b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/controls/MenuSelectHeading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,6 @@ export default function MenuSelectHeading({

const isCurrentlyParagraphOrHeading = selectedValue !== "";
const canSetParagraph = !!editor?.can().setParagraph();
// We have to pass a level when running `can`, so this is just an arbitrary
// one. And we have to check `currentLevel` to prevent all other heading
// levels from being disabled when Heading 1 is selected (see
// https://github.com/sjdemartini/mui-tiptap/issues/197).
const canSetHeading =
currentLevel === 1 || !!editor?.can().setHeading({ level: 1 });

// Figure out which settings the user has enabled with the heading extension
const enabledHeadingLevels: Set<Level> = useMemo(() => {
Expand All @@ -200,6 +194,17 @@ export default function MenuSelectHeading({
return new Set(headingExtension?.options.levels ?? []);
}, [editor]);

// We have to pass a level when running `can`, so this is just an arbitrary
// one that is enabled. And we have to check `currentLevel` to prevent all other heading
// levels from being disabled when Heading 1 is selected (see
// https://github.com/sjdemartini/mui-tiptap/issues/197).
const firstEnabledHeading = enabledHeadingLevels.values().next()
.value as Level;
const canSetHeading =
enabledHeadingLevels.size > 0 &&
(currentLevel === firstEnabledHeading ||
!!editor?.can().setHeading({ level: firstEnabledHeading }));

return (
// We currently have to specify that the value is of type
// `HeadingOptionValue | ""` rather than just `HeadingOptionValue` due to
Expand Down

0 comments on commit 609135b

Please sign in to comment.