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

[Search][a11y] Fixing connectors pageHeader hierarchy content #201359

Merged
merged 7 commits into from
Nov 26, 2024

Conversation

JoseLuisGJ
Copy link
Contributor

@JoseLuisGJ JoseLuisGJ commented Nov 22, 2024

Replace the existing ConnectorNameAndDescription component with separate ConnectorName and ConnectorDescription components for improved accessibility as pointed out in this issue #198001 . Now only the H1 wraps the Title and the Descriptions is out of it.

Before:
image
image

After:

CleanShot 2024-11-22 at 12 56 25@2x

@JoseLuisGJ JoseLuisGJ requested a review from a team as a code owner November 22, 2024 11:47
@JoseLuisGJ JoseLuisGJ self-assigned this Nov 22, 2024
@JoseLuisGJ JoseLuisGJ added release_note:fix v9.0.0 Team:Search backport:prev-major Backport to (8.x, 8.17, 8.16) the previous major branch and other branches in development backport:version Backport to applied version labels v8.17.0 v8.16.1 Project:Accessibility labels Nov 22, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-accessibility (Project:Accessibility)

@JoseLuisGJ JoseLuisGJ added backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes and removed v9.0.0 v8.17.0 v8.16.1 backport:version Backport to applied version labels backport:prev-major Backport to (8.x, 8.17, 8.16) the previous major branch and other branches in development release_note:fix labels Nov 22, 2024
Copy link
Contributor

@navarone-feekery navarone-feekery left a comment

Choose a reason for hiding this comment

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

Small request; can you provide a gif of you interacting with the title/description just to confirm the functionality still works?

@JoseLuisGJ
Copy link
Contributor Author

Sure @navarone-feekery :

CleanShot.2024-11-22.at.15.13.48.mp4

@jedrazb
Copy link
Member

jedrazb commented Nov 22, 2024

Screenshot 2024-11-22 at 15 16 42

could you expand the h1 tag to make sure no buttons are wrapped within h1 tag?

@JoseLuisGJ
Copy link
Contributor Author

JoseLuisGJ commented Nov 22, 2024

Good point @jedrazb there are still buttons within the h1 tag reading the expected behaviour from the issue ticket #198001:

Expected Result

Heading level is only announced one time (for one element, in this case title of connector). Heading level is not announced for description, nor for Save, Cancel buttons.

As commented here in the original issue ticket: we, from Search POV, can solve the issue regarding H1 not wrapping the description.

But bearing in mind that:

<EnterpriseSearchContentPageTemplate
      pageChrome={[...connectorsBreadcrumbs, connector?.name ?? '...']}
      pageViewTelemetry={tabId}
      isLoading={isLoading}
      pageHeader={{
        description: connector ? <ConnectorDescription connector={connector} /> : '...',
        pageTitle: connector ? <ConnectorName connector={connector} /> : '...',
        rightSideGroupProps: {
          gutterSize: 's',
          responsive: false,
          wrap: false,
        },
        rightSideItems: getHeaderActions(index, connector),
        tabs: tabs as Array<EuiTabProps & { label: React.ReactNode }>,
      }}
    >
      {selectedTab?.content || null}
</EnterpriseSearchContentPageTemplate>
  1. PageHeader.PageTitle renders the content wrapped in a H1 by default
  2. Within the ConnectorName we provide. We use and consume this EUI component EuiInlineEditTitle which renders these two buttons. So this part would be so hard to fix due to is part of the global PageTemplate we use. So we should decide if that's OK leaving this buttons within H1 oterwise we should think about remove completely the edit inline feature for titles to get the accessibility compliance.

CleanShot 2024-11-22 at 15 39 46@2x

@jedrazb
Copy link
Member

jedrazb commented Nov 25, 2024

@JoseLuisGJ got it thank you for sharing context, agreed that the fix for the h1 wrap is non-obvious and would involve adapting how page header and edit inline components are designed. If we can navigate the website with keyboard only and have reasonable voice over notifications I guess this should be fine

@JoseLuisGJ JoseLuisGJ changed the title [Search][a11y] Fixing connectors pageHeader hirarchy content [Search][a11y] Fixing connectors pageHeader hierarchy content Nov 25, 2024
@JoseLuisGJ
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@jedrazb jedrazb left a comment

Choose a reason for hiding this comment

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

The code duplication is the issue for me. I don't like that we duplicate most of logic between the _description and _name files, I asked copilot to refactor those files and create a HOC, Im sharing the suggestion as I like the structyre (though please validate! as I see that it lost e.g. heading="h1" prop for title):

HOC component suggestion
import React, { ChangeEvent, useEffect, useState } from 'react';
import { EuiFlexItem, EuiInlineEditText, EuiInlineEditTitle } from '@elastic/eui';
import { useActions, useValues } from 'kea';
import { i18n } from '@kbn/i18n';
import { Connector } from '@kbn/search-connectors';
import { ConnectorNameAndDescriptionLogic } from './connector_name_and_description_logic';

interface ConnectorFieldProps {
  connector: Connector;
  field: 'name' | 'description'; // The field to edit
  isTitle?: boolean; // Whether to render a title (`EuiInlineEditTitle`) or text (`EuiInlineEditText`)
}

export const ConnectorField: React.FC<ConnectorFieldProps> = ({ connector, field, isTitle }) => {
  const [value, setValue] = useState<string | null>(connector[field]);
  const [resolverObject, setResolverObject] = useState({
    rej: () => {},
    res: () => {},
  });
  const { saveNameAndDescription, setConnector } = useActions(ConnectorNameAndDescriptionLogic);
  const { status, isLoading, isFailed, isSuccess } = useValues(ConnectorNameAndDescriptionLogic);

  useEffect(() => {
    setConnector(connector);
  }, [connector]);

  useEffect(() => {
    if (isSuccess) resolverObject.res(true);
    if (isFailed) resolverObject.rej();
  }, [status]);

  const getValidationPromiseResolvers = () => {
    const resolvers = {
      rej: () => {},
      res: () => {},
    };
    const promise = new Promise((resolve, reject) => {
      resolvers.res = resolve;
      resolvers.rej = reject;
    });
    setResolverObject(resolvers);
    return promise;
  };

  const handleSave = async (newValue: string) => {
    setValue(newValue);
    saveNameAndDescription({ ...connector, [field]: newValue });
    return getValidationPromiseResolvers();
  };

  const handleCancel = (previousValue: string) => {
    setValue(previousValue);
  };

  const Component = isTitle ? EuiInlineEditTitle : EuiInlineEditText;

  return (
    <EuiFlexItem grow={false}>
      <Component
        inputAriaLabel={i18n.translate(
          `xpack.enterpriseSearch.content.connectors.nameAndDescription.${field}.ariaLabel`,
          {
            defaultMessage: `Edit connector ${field}`,
          }
        )}
        placeholder={i18n.translate(
          `xpack.enterpriseSearch.content.connectors.nameAndDescription.${field}.placeholder`,
          {
            defaultMessage: field === 'name' ? 'Add a name to your connector' : 'Add a description',
          }
        )}
        value={value || ''}
        isLoading={isLoading}
        isInvalid={field === 'name' && !value?.trim()}
        size="m"
        editModeProps={{
          cancelButtonProps: { onClick: () => handleCancel(connector[field] || '') },
          formRowProps: field === 'name' && !value?.trim() ? {
            error: [
              i18n.translate(
                'xpack.enterpriseSearch.content.nameAndDescription.name.error.empty',
                { defaultMessage: 'Connector name cannot be empty' }
              ),
            ],
          } : undefined,
          inputProps: { readOnly: isLoading },
        }}
        onSave={handleSave}
        onChange={(e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value)}
        onCancel={() => handleCancel(connector[field] || '')}
      />
    </EuiFlexItem>
  );
};

and the e.g. connector name def:

import React from 'react';
import { Connector } from '@kbn/search-connectors';
import { ConnectorField } from './ConnectorField';

export const ConnectorName: React.FC<{ connector: Connector }> = ({ connector }) => (
  <ConnectorField connector={connector} field="name" isTitle />
);

and description

import React from 'react';
import { Connector } from '@kbn/search-connectors';
import { ConnectorField } from './ConnectorField';

export const ConnectorDescription: React.FC<{ connector: Connector }> = ({ connector }) => (
  <ConnectorField connector={connector} field="description" />
);

@artem-shelkovnikov
Copy link
Member

I am also really away from accessibility/Kibana and do not fully understand what happens here.

Why does the accessibility improve? Is it because we now have 2 separate HTML sections that are handled better by the tools that do text-to-voice?

@jedrazb
Copy link
Member

jedrazb commented Nov 26, 2024

Why does the accessibility improve?

We no longer wrap description in h1 (page title) tag from what i understand

@JoseLuisGJ
Copy link
Contributor Author

Thanks @jedrazb and @artem-shelkovnikov , indeed now H1 tag only renders the Title content and the description inline edit element it below it.

@jedrazb I refactored these components using a HOC and sharing code as your suggestion and with the help of Copilot as well.

Copy link
Member

@jedrazb jedrazb left a comment

Choose a reason for hiding this comment

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

LGTM, small comment

Copy link
Member

@jedrazb jedrazb left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for helping with the a11y issues!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
enterpriseSearch 2313 2315 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
enterpriseSearch 2.6MB 2.6MB -324.0B

History

cc @JoseLuisGJ

@JoseLuisGJ JoseLuisGJ merged commit 8487bc8 into elastic:main Nov 26, 2024
21 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12033090516

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 26, 2024
…c#201359)

Replace the existing `ConnectorNameAndDescription` component with
separate `ConnectorName` and `ConnectorDescription` components for
improved accessibility as pointed out in this issue
elastic#198001 . Now only the H1 wraps
the Title and the Descriptions is out of it.

Before:

![image](https://github.com/user-attachments/assets/e3b297a9-31e1-4471-a638-2166185551e6)

![image](https://github.com/user-attachments/assets/c9030e25-b067-40b5-b4f6-d07a52d16a30)

After:

![CleanShot 2024-11-22 at 12 56
25@2x](https://github.com/user-attachments/assets/41a8cbf9-e609-4fbb-b1cd-3f9256bcaa8e)

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 8487bc8)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 26, 2024
…201359) (#201806)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Search][a11y] Fixing connectors pageHeader hierarchy content
(#201359)](#201359)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"José Luis
González","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-26T14:48:15Z","message":"[Search][a11y]
Fixing connectors pageHeader hierarchy content (#201359)\n\nReplace the
existing `ConnectorNameAndDescription` component with\r\nseparate
`ConnectorName` and `ConnectorDescription` components for\r\nimproved
accessibility as pointed out in this
issue\r\nhttps://github.com//issues/198001 . Now only the
H1 wraps\r\nthe Title and the Descriptions is out of
it.\r\n\r\nBefore:\r\n\r\n![image](https://github.com/user-attachments/assets/e3b297a9-31e1-4471-a638-2166185551e6)\r\n\r\n![image](https://github.com/user-attachments/assets/c9030e25-b067-40b5-b4f6-d07a52d16a30)\r\n\r\nAfter:\r\n\r\n![CleanShot
2024-11-22 at 12
56\r\n25@2x](https://github.com/user-attachments/assets/41a8cbf9-e609-4fbb-b1cd-3f9256bcaa8e)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"8487bc83d9ebc20ec2e1a5a18286a2a522346e6c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Project:Accessibility","release_note:skip","v9.0.0","Team:Search","backport:prev-minor"],"title":"[Search][a11y]
Fixing connectors pageHeader hierarchy
content","number":201359,"url":"https://github.com/elastic/kibana/pull/201359","mergeCommit":{"message":"[Search][a11y]
Fixing connectors pageHeader hierarchy content (#201359)\n\nReplace the
existing `ConnectorNameAndDescription` component with\r\nseparate
`ConnectorName` and `ConnectorDescription` components for\r\nimproved
accessibility as pointed out in this
issue\r\nhttps://github.com//issues/198001 . Now only the
H1 wraps\r\nthe Title and the Descriptions is out of
it.\r\n\r\nBefore:\r\n\r\n![image](https://github.com/user-attachments/assets/e3b297a9-31e1-4471-a638-2166185551e6)\r\n\r\n![image](https://github.com/user-attachments/assets/c9030e25-b067-40b5-b4f6-d07a52d16a30)\r\n\r\nAfter:\r\n\r\n![CleanShot
2024-11-22 at 12
56\r\n25@2x](https://github.com/user-attachments/assets/41a8cbf9-e609-4fbb-b1cd-3f9256bcaa8e)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"8487bc83d9ebc20ec2e1a5a18286a2a522346e6c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201359","number":201359,"mergeCommit":{"message":"[Search][a11y]
Fixing connectors pageHeader hierarchy content (#201359)\n\nReplace the
existing `ConnectorNameAndDescription` component with\r\nseparate
`ConnectorName` and `ConnectorDescription` components for\r\nimproved
accessibility as pointed out in this
issue\r\nhttps://github.com//issues/198001 . Now only the
H1 wraps\r\nthe Title and the Descriptions is out of
it.\r\n\r\nBefore:\r\n\r\n![image](https://github.com/user-attachments/assets/e3b297a9-31e1-4471-a638-2166185551e6)\r\n\r\n![image](https://github.com/user-attachments/assets/c9030e25-b067-40b5-b4f6-d07a52d16a30)\r\n\r\nAfter:\r\n\r\n![CleanShot
2024-11-22 at 12
56\r\n25@2x](https://github.com/user-attachments/assets/41a8cbf9-e609-4fbb-b1cd-3f9256bcaa8e)\r\n\r\n---------\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"8487bc83d9ebc20ec2e1a5a18286a2a522346e6c"}}]}]
BACKPORT-->

Co-authored-by: José Luis González <[email protected]>
paulinashakirova pushed a commit to paulinashakirova/kibana that referenced this pull request Nov 26, 2024
…c#201359)

Replace the existing `ConnectorNameAndDescription` component with
separate `ConnectorName` and `ConnectorDescription` components for
improved accessibility as pointed out in this issue
elastic#198001 . Now only the H1 wraps
the Title and the Descriptions is out of it.

Before:

![image](https://github.com/user-attachments/assets/e3b297a9-31e1-4471-a638-2166185551e6)

![image](https://github.com/user-attachments/assets/c9030e25-b067-40b5-b4f6-d07a52d16a30)

After:

![CleanShot 2024-11-22 at 12 56
25@2x](https://github.com/user-attachments/assets/41a8cbf9-e609-4fbb-b1cd-3f9256bcaa8e)

---------

Co-authored-by: Elastic Machine <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
…c#201359)

Replace the existing `ConnectorNameAndDescription` component with
separate `ConnectorName` and `ConnectorDescription` components for
improved accessibility as pointed out in this issue
elastic#198001 . Now only the H1 wraps
the Title and the Descriptions is out of it.

Before:

![image](https://github.com/user-attachments/assets/e3b297a9-31e1-4471-a638-2166185551e6)

![image](https://github.com/user-attachments/assets/c9030e25-b067-40b5-b4f6-d07a52d16a30)

After:

![CleanShot 2024-11-22 at 12 56
25@2x](https://github.com/user-attachments/assets/41a8cbf9-e609-4fbb-b1cd-3f9256bcaa8e)

---------

Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Project:Accessibility release_note:skip Skip the PR/issue when compiling release notes Team:Search v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants