OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
682 stars 95 forks source link

Outlook - Cursor moves to the bottom of body when body is changed with officejs #3290

Closed purelogiq closed 11 months ago

purelogiq commented 1 year ago

Provide required information needed to triage your issue

Your Environment

Expected behavior

After using setAsync to update a mailbox body in Outlook's compose window, the cursor remains at the same position or the default position (start of the body). (This also happens with prependAsync)

Current behavior

After using setAsync to update a mailbox body in Outlook's compose window, the cursor is placed at the end of the email body. (This also happens with prependAsync)

Steps to reproduce

  1. Create Outlook signature and set to be default on new messages. (Technically this happens even without the signature but it is more obvious to see with one)
  2. Create extension that calls setAsync in anyway e.g. to add <div>test</div> to the body. Example code (might not work 100%)
    
    // This might not work as written but its the general idea
    import Office from 'Office';
    const {
    context: {
    mailbox: { item },
    },
    CoercionType,
    } = Office;

item.body.getAsync(CoercionType.HTML, (response) => { const el = document.createElement('div'); el.innerHTML = response.value; el.firstChild.insertAdjacentHTML('beforeend', '

test
'); const newHtml = el.firstChild.innerHTML; item.body.setAsync(newHtml, { coercionType: CoercionType.Html, }, ()=>{}); });


3. Note that the cursor is placed at the end of the body (more obvious if you tab through from the to/from/subject fields to the body)

## Link to live example(s)

# Provide additional details

## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
This is especially obvious when the user is tabbing through the To, From, Subject fields and to the body. The [HubSpot Sales Outlook extension](https://appsource.microsoft.com/en-us/product/office/WA104381257?hsCtaTracking=f69a7c01-dece-4bb7-a130-4e87a430c506%7C5b0e7696-51cb-4649-88b8-8edec830c191&exp=ubp8) which I work on has users that complain that whenever they tab through to the email body their cursor is placed at the end. This because our extension adds an email tracking pixel using office.js.

## Useful logs
### Tabbing between Header Fields to the Body - Cursor defaults to end of body because of our extension using office.js
<!--- Please include any of the following logs that may help us debugging your issue -->

https://user-images.githubusercontent.com/7828780/231022831-46cf3131-15ec-41ce-b2c7-5887e16c759b.mp4

## Related issues
https://github.com/OfficeDev/office-js/issues/1625
exextoc commented 1 year ago

Thanks for reporting the issue. It has been put on our backlog. We unfortunately have no timelines to share at this point.

Internal tracking Id: OWA: 202986 Mac: 7502526, 7795201

exextoc commented 11 months ago

We have updated the documentation here: https://learn.microsoft.com/en-us/javascript/api/outlook/office.body?view=outlook-js-preview. Resolving the issue.