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

Customize scroll behavior #3653

Merged
merged 13 commits into from
Jan 20, 2021
Merged

Conversation

compulim
Copy link
Contributor

@compulim compulim commented Jan 4, 2021

Fixes #2884.

Changelog Entry

Added

  • Added new style options to customize auto-scroll, by @compulim in PR #3653
    • Set autoScrollSnapOnActivity to true to pause auto-scroll after more than one activity is shown, or a number to pause after X number of activities
    • Set autoScrollSnapOnPage to true to pause auto-scroll when a page is filled, or a number between 0 and 1 to pause after % of page is filled
    • Set autoScrollSnapOnActivityOffset and autoScrollSnapOnPageOffset to a number (in pixels) to overscroll/underscroll after the pause
  • Supports multiple transcripts in a single composition, by @compulim in PR #3653

Description

Added style options to customize scroll behavior by pausing at specified "snap point".

Currently, support 2 snap points:

  • Pause after a percentage of page is filled
  • Pause after X activities arrived

In additional to snap points, 2 more options to specify number of pixels to overscroll or underscroll. If both options are specified, it will use the value that would pause the auto-scroll sooner.

The following video demonstrates the pause after 2 activities and 100 pixels. The cyan color indicates acknowledged activities and orange color indicates recently arrived activities. Equivalent to setting:

styleOptions = {
  autoScrollPauseOnActivity: 2,
  autoScrollPauseOnActivityOffset: 100
};
Media1.mp4

Design

Default behavior

By default, we did not enable this feature. We should consult our UX team before turning it on by default.

Activities acknowledgement

To pause, only unacknowledged activities are taken into account. For example, the page will pause after it filled with activities the user didn't positively indicate they have been read.

Acknowledgement means: activity is positively acknowledged by the user. If the user does not interact on Web Chat, no activities should be acknowledged.

Currently, we use 2 signals for indicating acknowledgement:

  • When the user scroll to the bottom of the page
  • When the user sent a message

The signals above positively identify the user read the content.

Since the DLJS and other chat adapters do not keep this acknowledgement information, we will assume, when Web Chat started, all activities are acknowledged (e.g. restoring from conversation history). And it will stop auto-acknowledging when the user send their first message.

Due to the limitation of chat adapter, we recommend content author not to send initial activities (a.k.a. welcome messages) longer than a page.

Allowing multiple instances of <BasicTranscript>

Last October, when we work on the feature to refactor some React components into API layer, the way we refactor <BasicTranscript> does not allow multiple instances of it inside the same composition (i.e. <Composer>).

In this PR, we also addressed it by allowing multiple instances of <BasicTranscript>, such as:

<Composer directLine={...}>
  <BasicTranscript />
  <BasicTranscript />
</Composer>

Resolving #2884

In #2884, the developer prefers to pause "after 1 activity and 2.5 lines of text". Since line of text is not trivial to measure in HTML, we fallback to pixels instead.

To resolve #2884, the developer should set the following style options:

styleOptions = {
  autoScrollPauseOnActivity: true,
  autoScrollPauseOnActivityOffset: 100
};

Specific Changes

  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@compulim compulim force-pushed the feat-custom-scroll branch from cd5ea94 to 39bf542 Compare January 4, 2021 21:02

const scrollable = document.querySelector('.webchat__basic-transcript__scrollable');

expect(scrollable.scrollTop).toBe(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one test validation failed as well due to inequality due to rounding to nearest decimal
Expected: 353
Received: 352.6666564941406
not sure if you saw same error before or it is a problem with my browser/display?
and i am also thinking if we could give a margin of error to make test more resilient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you running the tests under Docker (i.e. via Jest)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

// 1. The condition will become solely "at the bottom of the transcript"
// 2. Auto-scroll will always scroll the transcript to the bottom
// 3. Web Chat will always acknowledge all activities as it is at the bottom
// 4. Acknowledge flag become useless
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "therefore... + explanation"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added:

//      5. Therefore, even the developer set "pause after 3 activities", if activities are coming in at a slow pace (not batched in a single render)
//         Web Chat will keep scrolling and not snapped/paused

Copy link
Contributor

@corinagum corinagum Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see 5. added to the code yet, but looks good.

Suggested change
// 4. Acknowledge flag become useless
// 4. Acknowledge flag becomes useless
// 5. Therefore, when the developer sets "pause after 3 activities", if activities are coming in at a slow pace (not batched in a single render)
// Web Chat will keep scrolling and not become snapped/paused

Copy link
Contributor

@corinagum corinagum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - I approved (with comments), but since @amal-khalaf is reviewing as well, I recommend waiting for her approval too.

@Sandy2725
Copy link

Hi @compulim ,

Hope you are doing well.

I have two queries.

1.If we pass the scroll after 1 activity its working fine. But if we have a large content in the 1st message only again the scrollbar is going down. is there any way to focus on at staring of that first message.
2. And if response contains more than (150 or 200 words) or 10 lines. can we add readmore link and then when we click on readmore user can see rest. like after 100 words or 5 lines. for buttons we have readmore but inside the message response do we have that.

Thanks.

@Sandy2725
Copy link

HI @compulim ,

Can we implement this custom scroll behavior for specific responses. Is there any possibility to implement for only few responses.

styleOptions = {
autoScrollPauseOnActivity: 2,
autoScrollPauseOnActivityOffset: 100
};

Thanks .

@Elephantei
Copy link

After updating the framwork-sdk to 4.12.1 and setting the following styleOptions this still doesn't work:

version:
<script src="https://cdn.botframework.com/botframework-webchat/4.12.1/webchat-es5.js" integrity_no="sha384-YT//LqZJgkEXrmVxm6RZJKs4dSZJQo5kEX0tE9dP1XaOaVsC7NEvwnlP2gW2KWcl" crossorigin="anonymous"></script>

Styling options added for the chat rendering options:

window.WebChat.renderWebChat(
  {
    directLine: window.WebChat.createDirectLine({
      token: process.env.TOKEN,
    }),
    onTelemetry: handleTelemetry,
    store: store,
    styleOptions: {
      hideUploadButton: true,
      autoScrollPauseOnActivity: 2,
      autoScrollPauseOnActivityOffset: 100
    },
  },
  document.getElementById("webchat")
); 

Can someone shed some light on it?

@Sandy2725
Copy link

Hi @Elephantei ,

Try with below style options.

autoScrollSnapOnActivity:2,
autoScrollSnapOnPage:true,
autoScrollSnapOnActivityOffset:100,

@Jakob-vdH
Copy link

Hi @Sandy2725

thank you for your help, this worked for us really well for a bit.
Just to recap, with the following settings, the webchat was always scrolling to the top edge of a new message / adaptive card, if some messages were in the chat, that were longer that the view, which was awesome behavior.

autoScrollSnapOnActivity:2,
autoScrollSnapOnPage:true,
autoScrollSnapOnActivityOffset:100,

But now we updated to the last webchat version (4.15.2) and this just stopped working, not scrolling anymore at all as soon as the "page" is full with messages. I guess this is intended behavior of autoScrollSnapOnPage.
Is there an option to always scroll to the top of a message if it is longer than the current view?
We tried recreating the initial behavior using the autoScrollSnap options, but sadly did not succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Ability to customize scroll behaviour in WebChat V4
6 participants