diff --git a/change/@ni-nimble-components-42ffbdab-86c2-4075-a77e-a24e14afc857.json b/change/@ni-nimble-components-42ffbdab-86c2-4075-a77e-a24e14afc857.json new file mode 100644 index 0000000000..e70e613908 --- /dev/null +++ b/change/@ni-nimble-components-42ffbdab-86c2-4075-a77e-a24e14afc857.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Removed disable-editing attribute from the rich text mention users view component for rendering @mention in editor and viewer", + "packageName": "@ni/nimble-components", + "email": "123377523+vivinkrishna-ni@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/nimble-components/src/rich-text-mention/base/view/index.ts b/packages/nimble-components/src/rich-text-mention/base/view/index.ts index 7a56e50556..7482d15e0e 100644 --- a/packages/nimble-components/src/rich-text-mention/base/view/index.ts +++ b/packages/nimble-components/src/rich-text-mention/base/view/index.ts @@ -22,13 +22,4 @@ export class RichTextMentionView extends FoundationElement { */ @attr({ attribute: 'mention-label' }) public mentionLabel?: string; - - /** - * Whether to render the mention node in view mode or in edit mode - * - * @public - * HTML Attribute: disable-editing - */ - @attr({ mode: 'boolean', attribute: 'disable-editing' }) - public disableEditing = false; } diff --git a/packages/nimble-components/src/rich-text-mention/users/view/styles.ts b/packages/nimble-components/src/rich-text-mention/users/view/styles.ts index 8b68d0b798..85d20362ba 100644 --- a/packages/nimble-components/src/rich-text-mention/users/view/styles.ts +++ b/packages/nimble-components/src/rich-text-mention/users/view/styles.ts @@ -2,11 +2,8 @@ import { css } from '@microsoft/fast-element'; import { display } from '@microsoft/fast-foundation'; import { mentionFont, - mentionDisabledFontColor, - bodyFontColor, - bodyFont, - bodyDisabledFontColor, - mentionFontColor + mentionFontColor, + mentionDisabledFontColor } from '../../../theme-provider/design-tokens'; export const styles = css` @@ -14,34 +11,14 @@ export const styles = css` :host { box-sizing: border-box; - font: ${bodyFont}; - color: ${bodyFontColor}; - white-space: pre-wrap; + font: ${mentionFont}; } .control { - font: ${mentionFont}; color: ${mentionFontColor}; - display: none; - } - - :host([disable-editing]) .control { - display: inline; } :host([disabled]) .control { color: ${mentionDisabledFontColor}; } - - :host([disabled]) { - color: ${bodyDisabledFontColor}; - } - - :host([disable-editing]) { - font: ${mentionFont}; - } - - :host([disable-editing]) slot { - display: none; - } `; diff --git a/packages/nimble-components/src/rich-text-mention/users/view/template.ts b/packages/nimble-components/src/rich-text-mention/users/view/template.ts index 2058e93d06..5a41d33907 100644 --- a/packages/nimble-components/src/rich-text-mention/users/view/template.ts +++ b/packages/nimble-components/src/rich-text-mention/users/view/template.ts @@ -1,10 +1,6 @@ import { html } from '@microsoft/fast-element'; import type { RichTextMentionUsersView } from '.'; -// Setting `contenteditable="true"` on the slot serves as a workaround to address the issue in the Chrome browser -// that arises when the mention user view is activated at the end of a line in the rich text editor while in edit mode. -// This can be removed when the below issue is resolved -// See: https://github.com/ni/nimble/issues/1659 export const template = html`@${x => x.mentionLabel}`; + >@${x => x.mentionLabel}`; diff --git a/packages/nimble-components/src/rich-text-mention/users/view/tests/rich-text-mention-users-view-matrix.stories.ts b/packages/nimble-components/src/rich-text-mention/users/view/tests/rich-text-mention-users-view-matrix.stories.ts index 4a04e8164c..a3997e50af 100644 --- a/packages/nimble-components/src/rich-text-mention/users/view/tests/rich-text-mention-users-view-matrix.stories.ts +++ b/packages/nimble-components/src/rich-text-mention/users/view/tests/rich-text-mention-users-view-matrix.stories.ts @@ -9,20 +9,12 @@ import { richTextMentionUsersViewTag } from '..'; import { bodyFont, bodyFontColor, - borderColor, - borderWidth, - mediumPadding, smallPadding } from '../../../../theme-provider/design-tokens'; - -const disableEditingStates = [ - ['In View Mode', false, true], - ['In Edit mode', false, false], - ['Disabled - In Edit mode', true, false], - ['Disabled - In View Mode', true, true] -] as const; - -type DisableEditingState = (typeof disableEditingStates)[number]; +import { + type DisabledState, + disabledStates +} from '../../../../utilities/tests/states'; const metadata: Meta = { title: 'Tests/Rich Text Mention: User', @@ -34,10 +26,9 @@ const metadata: Meta = { export default metadata; const component = ([ - name, - disabled, - disableEditing -]: DisableEditingState): ViewTemplate => html` + disabledName, + disabled +]: DisabledState): ViewTemplate => html` -
- User mention: - <${richTextMentionUsersViewTag} - mention-href="user:1" - mention-label="John Doe" >@John Doe - (Mention View Enabled Editing) + (Mention View ${() => disabledName})
`; -export const richTextMentionUserViewThemeMatrix: StoryFn = createMatrixThemeStory(createMatrix(component, [disableEditingStates])); - -export const richTextMentionUserViewEditEnabledThemeMatrix: StoryFn = createMatrixThemeStory(createMatrix(componentEditingMode)); +export const richTextMentionUserViewThemeMatrix: StoryFn = createMatrixThemeStory(createMatrix(component, [disabledStates])); diff --git a/packages/nimble-components/src/rich-text-mention/users/view/tests/rich-text-mention-users-view.spec.ts b/packages/nimble-components/src/rich-text-mention/users/view/tests/rich-text-mention-users-view.spec.ts index d5d2575b3a..e917268d1c 100644 --- a/packages/nimble-components/src/rich-text-mention/users/view/tests/rich-text-mention-users-view.spec.ts +++ b/packages/nimble-components/src/rich-text-mention/users/view/tests/rich-text-mention-users-view.spec.ts @@ -11,7 +11,6 @@ async function setup(): Promise> { html`<${richTextMentionUsersViewTag} mention-href="users:1" mention-label="John Doe" - disable-editing >@John Doe` ); diff --git a/packages/nimble-components/src/rich-text/editor/models/create-tiptap-editor.ts b/packages/nimble-components/src/rich-text/editor/models/create-tiptap-editor.ts index dcf7da74e5..fb83eec703 100644 --- a/packages/nimble-components/src/rich-text/editor/models/create-tiptap-editor.ts +++ b/packages/nimble-components/src/rich-text/editor/models/create-tiptap-editor.ts @@ -209,12 +209,7 @@ function createCustomMentionExtension( renderHTML({ node, HTMLAttributes }) { return [ config.viewElement, - mergeAttributes( - this.options.HTMLAttributes, - HTMLAttributes, - // disable-editing is a boolean attribute - { 'disable-editing': '' } - ), + mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), this.options.renderLabel({ options: this.options, node @@ -224,13 +219,7 @@ function createCustomMentionExtension( }).configure({ suggestion: { char: config.character, - /** - * When rendering the view element as a decoration tag for suggestions, - * it leads to the deletion of the entire suggested word in Safari when pressing backspace. - * See: https://github.com/ni/nimble/issues/1716 - * When addressed, re-enable the view element as follows: - * decorationTag: config.viewElement, - */ + decorationClass: 'nimble-mention-view-edit', pluginKey: new PluginKey(config.key), allowSpaces: true, render: () => { diff --git a/packages/nimble-components/src/rich-text/editor/styles.ts b/packages/nimble-components/src/rich-text/editor/styles.ts index 7a7b8b9f1b..b096cab1f3 100644 --- a/packages/nimble-components/src/rich-text/editor/styles.ts +++ b/packages/nimble-components/src/rich-text/editor/styles.ts @@ -168,7 +168,7 @@ export const styles = css` margin-block-end: 0; } - li > p { + .ProseMirror li > p { margin-block: 0; } @@ -222,6 +222,15 @@ export const styles = css` ${/** End of anchor styles */ ''} + ${/* Shared styles for all mention views at edit time. */ ''} + .ProseMirror .nimble-mention-view-edit { + color: ${bodyFontColor}; + } + + :host([disabled]) .ProseMirror .nimble-mention-view-edit { + color: ${bodyDisabledFontColor}; + } + .footer-section { display: flex; justify-content: space-between; diff --git a/packages/nimble-components/src/rich-text/editor/tests/rich-text-editor-mention.spec.ts b/packages/nimble-components/src/rich-text/editor/tests/rich-text-editor-mention.spec.ts index 24d2937387..fdd38c12ea 100644 --- a/packages/nimble-components/src/rich-text/editor/tests/rich-text-editor-mention.spec.ts +++ b/packages/nimble-components/src/rich-text/editor/tests/rich-text-editor-mention.spec.ts @@ -989,6 +989,16 @@ describe('RichTextEditor user mention via template', () => { expect(pageObject.isMentionListboxOpened()).toBeTrue(); }); }); + + it('should get `span` and expected class name when @ character is added into the editor', async () => { + await pageObject.setEditorTextContent('@mention'); + + expect(pageObject.getMarkdownRenderedTagNames()).toEqual(['P', 'SPAN']); + expect(pageObject.getEditorFirstChildTextContent()).toBe('@mention'); + expect(pageObject.getEditorLastChildAttribute('class')).toBe( + 'nimble-mention-view-edit' + ); + }); }); describe('RichTextEditorMentionListbox', () => { diff --git a/packages/nimble-components/src/rich-text/models/markdown-parser.ts b/packages/nimble-components/src/rich-text/models/markdown-parser.ts index f67863ff68..6b211d3dfa 100644 --- a/packages/nimble-components/src/rich-text/models/markdown-parser.ts +++ b/packages/nimble-components/src/rich-text/models/markdown-parser.ts @@ -133,8 +133,7 @@ export class RichTextMarkdownParser { currentMention.viewElement, { 'mention-href': href, - 'mention-label': displayName, - 'disable-editing': true + 'mention-label': displayName } ]; }