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

[EuiInlineEdit] (POC Review) Create Component Directory and Base Functionality #6533

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ import { IconExample } from './views/icon/icon_example';

import { ImageExample } from './views/image/image_example';

import { InlineEditExample } from './views/inline_edit/inline_edit_example';

import { InnerTextExample } from './views/inner_text/inner_text_example';

import { KeyPadMenuExample } from './views/key_pad_menu/key_pad_menu_example';
Expand Down Expand Up @@ -557,6 +559,7 @@ const navigation = [
HealthExample,
IconExample,
ImageExample,
InlineEditExample,
ListGroupExample,
LoadingExample,
NotificationEventExample,
Expand Down
93 changes: 93 additions & 0 deletions src-docs/src/views/inline_edit/inline_edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React, { useState } from 'react';

import {
EuiInlineEdit,
EuiFieldText,
EuiComboBox,
EuiTextArea,
EuiComboBoxProps,
EuiHorizontalRule,
EuiSpacer,
} from '../../../../src/components';

const optionsStatic = [
{
label: 'Titan',
'data-test-subj': 'titanOption',
},
{
label: 'Enceladus is disabled',
disabled: true,
},
{
label: 'Mimas',
},
{
label: 'Dione',
},
{
label: 'Iapetus',
},
{
label: 'Phoebe',
},
{
label: 'Rhea',
},
{
label:
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology",
},
{
label: 'Tethys',
},
{
label: 'Hyperion',
},
];

export default () => {
const [options, setOptions] = useState(optionsStatic);
const [selectedOptions, setSelected] = useState([options[2], options[4]]);

const onChange = (selectedOptions: any) => {
setSelected(selectedOptions);
};

return (
<>
{/* Base components */}
<h3>EuiInlineEdit - Text</h3>
<EuiInlineEdit
editViewType={EuiFieldText}
Comment on lines +60 to +62
Copy link
Contributor

Choose a reason for hiding this comment

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

When I started reviewing these with VoiceOver, I noticed it was reading back the input (or textarea) text but not the heading I presumed was the visual / accessible label. I think you could go a couple of directions here:

  1. Add documentation encouraging users to set unique IDs on each heading and pass that ID into an aria-labelledby prop in the EuiInlineEdit when it's in edit state.
  2. Make label a required prop so it adds a visual and accessible label to the input. This gets in the way of the heading text in your examples.
  3. Set a required aria-label prop on the EuiInlineEdit component that gets passed to the input or textarea. This is my least favorite option.

This change feels like it could affect visual and structural order, so happy to discuss it more next week and look for a good working solution.

defaultValue="helloWorld"
editViewTypeProps={{ id: 'hello' }}
/>
<EuiHorizontalRule />

<h3>EuiInlineEdit - Textarea</h3>
<EuiInlineEdit
editViewType={EuiTextArea}
defaultValue="Tiramisu jelly beans sweet croissant macaroon topping. Gummies fruitcake sesame snaps lollipop chocolate cake lemon drops icing. Cake cake croissant ice cream jujubes donut toffee. Gummies jelly tiramisu cheesecake brownie icing gummi bears candy canes."
editViewTypeProps={{ id: 'hello' }}
/>
<EuiHorizontalRule />

<h3>EuiInlineEdit - Select</h3>
<EuiInlineEdit
editViewType={EuiComboBox}
editViewTypeProps={{
isClearable: true,
options: options,
placeholder: 'Select or create options',
selectedOptions: selectedOptions,
onChange: onChange,
'data-test-subj': 'demoComboBox',
'aria-label': 'Accessible screen reader label',
autoFocus: true,
}}
/>
<EuiHorizontalRule />
</>
);
};
40 changes: 40 additions & 0 deletions src-docs/src/views/inline_edit/inline_edit_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';

import { GuideSectionTypes } from '../../components';

import { EuiText, EuiInlineEdit } from '../../../../src';

import InlineEdit from './inline_edit';
const inlineEditSource = require('!!raw-loader!./inline_edit');

export const InlineEditExample = {
title: 'Inline edit',
intro: (
<>
<EuiText>
Hello! This is where the EuiInlineEdit documentation intro will go!
</EuiText>
</>
),
sections: [
{
title: 'Inline edit',
text: (
<>
<p>
Description needed: how to use the <strong>EuiInlineEdit</strong>{' '}
component.
</p>
</>
),
source: [
{
type: GuideSectionTypes.JS,
code: inlineEditSource,
},
],
demo: <InlineEdit />,
props: { EuiInlineEdit },
},
],
};
15 changes: 15 additions & 0 deletions src/components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,18 @@ export type RecursivePartial<T> = {
: RecursivePartial<T[P]>; // recurse for all non-array and non-primitive values
};
type NonAny = number | boolean | string | symbol | null;

// `Defaultize` copied out of @types/react
type Defaultize<P, D> = P extends any
? string extends keyof P
? P
: Pick<P, Exclude<keyof P, keyof D>> &
Partial<Pick<P, Extract<keyof P, keyof D>>> &
Partial<Pick<D, Exclude<keyof D, keyof P>>>
: never;

export type WithDefaultPropsApplied<
T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
> = T extends { defaultProps: infer D }
? Defaultize<ComponentProps<T>, D>
: ComponentProps<T>;
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export * from './icon';

export * from './image';

export * from './inline_edit';

export * from './inner_text';

export * from './i18n';
Expand Down
9 changes: 9 additions & 0 deletions src/components/inline_edit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { EuiInlineEdit } from './inline_edit';
Loading