microsoft / AdaptiveCards

A new way for developers to exchange card content in a common and consistent way.
https://adaptivecards.io
MIT License
1.7k stars 541 forks source link

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

Open guimafelipe opened 6 months ago

guimafelipe commented 6 months ago

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

jwoo-msft commented 5 months ago

@guimafelipe, when is this needed by?

guimafelipe commented 5 months ago

@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.

anna-dingler commented 3 months ago

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: