forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search][a11y] Fixing connectors pageHeader hierarchy content (elasti…
…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]>
- Loading branch information
1 parent
ca08a9b
commit 1e9d607
Showing
8 changed files
with
146 additions
and
156 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...lications/enterprise_search_content/components/connector_detail/connector_description.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { Connector } from '@kbn/search-connectors'; | ||
|
||
import { ConnectorField } from './connector_field'; | ||
|
||
export const ConnectorDescription: React.FC<{ connector: Connector }> = ({ connector }) => ( | ||
<ConnectorField connector={connector} field="description" /> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...ic/applications/enterprise_search_content/components/connector_detail/connector_field.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { ChangeEvent, useEffect, useState } from 'react'; | ||
|
||
import { useActions, useValues } from 'kea'; | ||
|
||
import { EuiFlexItem, EuiInlineEditText, EuiInlineEditTitle } from '@elastic/eui'; | ||
|
||
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(); | ||
if (isFailed) resolverObject.rej(); | ||
}, [status]); | ||
|
||
const getValidationPromiseResolvers = () => { | ||
const resolvers = { | ||
rej: () => {}, | ||
res: () => {}, | ||
}; | ||
const promise = new Promise<void>((resolve, reject) => { | ||
resolvers.res = resolve; | ||
resolvers.rej = reject; | ||
}); | ||
setResolverObject(resolvers); | ||
return promise; | ||
}; | ||
|
||
const handleSave = async (newValue: string) => { | ||
setValue(newValue); | ||
saveNameAndDescription({ ...connector, [field]: newValue }); | ||
await getValidationPromiseResolvers(); | ||
return true; | ||
}; | ||
|
||
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" | ||
heading={isTitle ? 'h1' : 'span'} | ||
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> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
...lic/applications/enterprise_search_content/components/connector_detail/connector_name.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { Connector } from '@kbn/search-connectors'; | ||
|
||
import { ConnectorField } from './connector_field'; | ||
|
||
export const ConnectorName: React.FC<{ connector: Connector }> = ({ connector }) => ( | ||
<ConnectorField connector={connector} field="name" isTitle /> | ||
); |
142 changes: 0 additions & 142 deletions
142
.../enterprise_search_content/components/connector_detail/connector_name_and_description.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters