AdaptiveCards icon indicating copy to clipboard operation
AdaptiveCards copied to clipboard

{Linked:Bug49658986;Linked:Bug49357192;Linked:Bug49357930}Feature request: Expose API to update a card with new data (template remains the same)

Open guimafelipe opened this issue 1 year ago • 3 comments

Target Platforms

AdaptiveCards-WinUI (=shared code with Universal)

SDK Version

1.0.2

Application Name

Dev Home, Windows Widget Dashboard

Problem Description

When the Adaptive Card of a Widget updates (either by an action pressed or not) and the focus is held inside the card, it is lost on the re-rendering. This happens because all the content of the card is redrawn when an update occurs.

The correct behavior should be the focus being kept to the equivalent control if the template didn't change from update to another. Or if the template changes, the focus should change to the AC itself. And the narrator should not narrate the control again when this change happen.

Screenshots

No response

Card JSON

{
  "type": "AdaptiveCard",
  "body": [
    {
      "type": "Image",
      "url": "${gpuGraphUrl}",
      "height": "${chartHeight}",
      "width": "${chartWidth}",
      "horizontalAlignment": "center"
    },
    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "items": [
            {
              "text": "%GPUUsage_Widget_Template/GPU_Usage%",
              "type": "TextBlock",
              "size": "small",
              "isSubtle": true
            },
            {
              "text": "${gpuUsage}",
              "type": "TextBlock",
              "size": "large",
              "weight": "bolder"
            }
          ]
        },
        {
          "type": "Column",
          "items": [
            {
              "text": "%GPUUsage_Widget_Template/GPU_Temperature%",
              "type": "TextBlock",
              "size": "small",
              "isSubtle": true,
              "horizontalAlignment": "right"
            },
            {
              "text": "${gpuTemp}",
              "type": "TextBlock",
              "size": "large",
              "weight": "bolder",
              "horizontalAlignment": "right"
            }
          ]
        }
      ]
    },
    {
      "text": "%GPUUsage_Widget_Template/GPU_Name%",
      "type": "TextBlock",
      "size": "small",
      "isSubtle": true
    },
    {
      "text": "${gpuName}",
      "type": "TextBlock",
      "size": "medium"
    }
  ],
  "actions": [
    {
      "type": "Action.Execute",
      "title": "%GPUUsage_Widget_Template/Next_GPU%",
      "verb": "NextItem"
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.5"
}

Sample Code Language

C#

Sample Code

No response

guimafelipe avatar Dec 04 '23 21:12 guimafelipe

@guimafelipe, when is this needed by?

jwoo-msft avatar Jan 05 '24 19:01 jwoo-msft

@guimafelipe, when is this needed by?

@jwoo-msft Currently as soon as possible, as this is affecting the accessibility grade.

This same issue is reported in two widgets and also in the configuration of two extensions. So it is duped four times in total.

guimafelipe avatar Jan 09 '24 17:01 guimafelipe

Moving this to feature request since an "update" mechanism is not explicitly supported in Adaptive Cards at this time.

I will update this ticket with a timeline after our team meeting next week.

Possible solutions from the team

For the host app: That said, something that might work well enough for this specific scenario would be for the host app to:

  1. Render the updated card, but don’t put it in the tree just yet
  2. Check if focus is currently on an element in the outdated card. If “no”: a. Swap in the updated card b. Stop processing
  3. Inspect element with focus. Does it have an id? If “no”: a. Swap in updated card b. Put focus somewhere “smart” (maybe the root of the card?) c. Stop processing
  4. Inspect updated card element. Does it have an element with the same id? (if “no”, go to step 3a)
  5. Swap updated card with old card in the visual tree
  6. Set focus to element found in step 4

Narrator issue mitigation: https://learn.microsoft.com/en-us/windows/apps/design/accessibility/custom-automation-peers

Full AC solution:

  • We will likely need to include templating library within AC.
  • UWP specific: We could also explore the idea of utilizing the UWP/WinUI data binding feature. When we create template and expand it, we allow UWP/WinUI data binding to be baked into our template expansion and have the data binding to take care of partial refresh.

anna-dingler avatar Mar 15 '24 17:03 anna-dingler