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

Updates Input Option #2365

Merged
merged 102 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
f67ea54
create Menu.styles
TheSonOfThomp May 24, 2024
20f46f6
installs descendants in menu
TheSonOfThomp May 24, 2024
0904c64
extract useMenuHeight
TheSonOfThomp May 24, 2024
4d5bcdb
init descendants
TheSonOfThomp May 24, 2024
393c2c7
pass onItemFocus from provider
TheSonOfThomp May 24, 2024
b0e2998
abstract out useUpdatedChildren
TheSonOfThomp May 24, 2024
b1e7561
creates useHighlightReducer
TheSonOfThomp May 24, 2024
08f8ba0
cleanup reducer
TheSonOfThomp May 28, 2024
6ef602d
skip disabled elements
TheSonOfThomp May 28, 2024
efbe6e2
implement descendant in submenu
TheSonOfThomp May 28, 2024
0bb6517
Merge branch 'main' into adam/menu-descendants
TheSonOfThomp May 28, 2024
7ffd0a9
Update yarn.lock
TheSonOfThomp May 28, 2024
80c9fa4
rm focus-visible styles
TheSonOfThomp May 28, 2024
233c14a
fix menu item list style
TheSonOfThomp May 28, 2024
9c8abb2
fix ts errors
TheSonOfThomp May 29, 2024
58106f1
rm deprecated hooks
TheSonOfThomp May 29, 2024
ec346e1
rm debug text
TheSonOfThomp May 29, 2024
24f8150
restructure test suite
TheSonOfThomp May 29, 2024
57cdf04
Create blue-crews-hope.md
TheSonOfThomp May 29, 2024
63e3b37
Updates stories
TheSonOfThomp May 29, 2024
b6da9f3
adds controlled story
TheSonOfThomp May 29, 2024
7fe747b
modernizes spec file
TheSonOfThomp May 29, 2024
9bdc2b2
Update Menu.stories.tsx
TheSonOfThomp May 30, 2024
fa89567
Update SplitButton.spec.tsx
TheSonOfThomp May 30, 2024
e03ddbe
update split button pkg.json
TheSonOfThomp May 30, 2024
a0073b1
Update yarn.lock
TheSonOfThomp May 30, 2024
6928362
Delete getNewIndex.ts
TheSonOfThomp May 30, 2024
ef27bdd
add // prettier-ignore
TheSonOfThomp May 30, 2024
138fead
mv HighlightReducer
TheSonOfThomp May 30, 2024
8ca217f
Update .gitignore
TheSonOfThomp May 30, 2024
6aad5b8
creates AriaLabelPropsWithChildren type
TheSonOfThomp May 31, 2024
f6d48b2
uses AriaLabelPropsWithChildren in InputOption
TheSonOfThomp May 31, 2024
67aa5fc
Create InputOptionContent generated story
TheSonOfThomp May 31, 2024
889ae44
InputOptionContent use tokens, extend className
TheSonOfThomp May 31, 2024
7c5969e
inputOptionThemeStyles use color tokens
TheSonOfThomp May 31, 2024
6ee4527
Update titleClassName
TheSonOfThomp May 31, 2024
5801f0a
create & use InputOptionContext
TheSonOfThomp May 31, 2024
a9eafdd
refactor inputOptionStyles
TheSonOfThomp May 31, 2024
1f8a3c4
fix inputoption icon placement & sizing
TheSonOfThomp May 31, 2024
62a4f4e
update icon hover styles
TheSonOfThomp May 31, 2024
63ff2e8
Update Avatar props (#2352)
TheSonOfThomp May 29, 2024
db32456
add turbo to clean (#2361)
shaneeza May 31, 2024
03ba539
pr
TheSonOfThomp May 31, 2024
04b39cf
Update .gitignore
TheSonOfThomp May 30, 2024
7b3a5cc
Merge branch 'adam/menu-refactor-LG-4120' into adam/input-option
TheSonOfThomp May 31, 2024
797478f
create Menu.styles
TheSonOfThomp May 24, 2024
057d795
installs descendants in menu
TheSonOfThomp May 24, 2024
ad52c53
extract useMenuHeight
TheSonOfThomp May 24, 2024
1ee644f
init descendants
TheSonOfThomp May 24, 2024
75fa4cd
pass onItemFocus from provider
TheSonOfThomp May 24, 2024
a35c30a
abstract out useUpdatedChildren
TheSonOfThomp May 24, 2024
4449ea4
creates useHighlightReducer
TheSonOfThomp May 24, 2024
0873fef
cleanup reducer
TheSonOfThomp May 28, 2024
44a67eb
skip disabled elements
TheSonOfThomp May 28, 2024
33977d0
implement descendant in submenu
TheSonOfThomp May 28, 2024
d45d8ae
Update yarn.lock
TheSonOfThomp May 28, 2024
3f1a824
rm focus-visible styles
TheSonOfThomp May 28, 2024
e1a866f
fix menu item list style
TheSonOfThomp May 28, 2024
58c1881
fix ts errors
TheSonOfThomp May 29, 2024
a418b7c
rm deprecated hooks
TheSonOfThomp May 29, 2024
357a34a
rm debug text
TheSonOfThomp May 29, 2024
ce2629c
restructure test suite
TheSonOfThomp May 29, 2024
f9831d2
Create blue-crews-hope.md
TheSonOfThomp May 29, 2024
c5ffcfa
Updates stories
TheSonOfThomp May 29, 2024
7535093
adds controlled story
TheSonOfThomp May 29, 2024
e91acea
modernizes spec file
TheSonOfThomp May 29, 2024
27633f8
Update Menu.stories.tsx
TheSonOfThomp May 30, 2024
2eceff7
adds preserveIconSpace. Update unique classnames
TheSonOfThomp Jun 3, 2024
4fb1f12
update component exports
TheSonOfThomp Jun 3, 2024
cc87812
Create big-wasps-fix.md
TheSonOfThomp Jun 3, 2024
a9dcf53
Create shaggy-cheetahs-ring.md
TheSonOfThomp Jun 3, 2024
74c8d77
Update big-wasps-fix.md
TheSonOfThomp Jun 3, 2024
82055b9
Renames selected -> checked
TheSonOfThomp Jun 3, 2024
34740be
creates separate InputOptionContent.stories
TheSonOfThomp Jun 3, 2024
0f54060
Update big-wasps-fix.md
TheSonOfThomp Jun 3, 2024
d8dfb7f
update active wedge to border.primary
TheSonOfThomp Jun 4, 2024
a7f403b
include darkMode in InputOptionContext
TheSonOfThomp Jun 4, 2024
6924e17
Merge branch 'adam/menu-descendants' of https://github.com/mongodb/le…
TheSonOfThomp Jun 4, 2024
96f11ae
rm old highlight reducer
TheSonOfThomp Jun 4, 2024
e72686c
rm unused descendant vars
TheSonOfThomp Jun 4, 2024
5632e05
rm checked styles
TheSonOfThomp Jun 4, 2024
b3cc78a
Update big-wasps-fix.md
TheSonOfThomp Jun 4, 2024
af19cb0
Merge branch 'adam/menu-descendants' into adam/input-option
TheSonOfThomp Jun 4, 2024
2ea172b
typo
TheSonOfThomp Jun 4, 2024
dbc8288
Merge branch 'adam/menu-descendants' into adam/input-option
TheSonOfThomp Jun 4, 2024
3cc07a4
revert wedge color to blue.base
TheSonOfThomp Jun 5, 2024
28b2311
revert icon height to default
TheSonOfThomp Jun 5, 2024
f4751c3
use disabled prop on `Description`
TheSonOfThomp Jun 5, 2024
f745228
add style changes to changeset
TheSonOfThomp Jun 5, 2024
7d1a2ea
updates text highlight color targeting
TheSonOfThomp Jun 5, 2024
62496eb
Merge branch 'adam/menu-refactor-LG-4120' into adam/menu-descendants
TheSonOfThomp Jun 5, 2024
302fbb9
Merge branch 'adam/menu-descendants' into adam/input-option
TheSonOfThomp Jun 5, 2024
d4f220d
revert implementing of Label component
TheSonOfThomp Jun 5, 2024
cd92b32
add description to highlight story
TheSonOfThomp Jun 5, 2024
4191652
Merge branch 'adam/menu-refactor-LG-4120' into adam/input-option
TheSonOfThomp Jun 5, 2024
88c1efe
Merge branch 'adam/menu-refactor-LG-4120' into adam/input-option
TheSonOfThomp Jun 5, 2024
0723687
Merge branch 'adam/menu-refactor-LG-4120' into adam/input-option
TheSonOfThomp Jun 6, 2024
6976dd5
Merge branch 'adam/menu-refactor-LG-4120' into adam/input-option
TheSonOfThomp Jun 10, 2024
e6a86c3
update changesets
TheSonOfThomp Jun 12, 2024
23e3513
add tests for AriaLabelPropsWithChildren
TheSonOfThomp Jun 12, 2024
b71d0b4
update documentation
TheSonOfThomp Jun 12, 2024
af9b324
Merge branch 'adam/menu-refactor-LG-4120' into adam/input-option
TheSonOfThomp Jun 13, 2024
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
35 changes: 35 additions & 0 deletions .changeset/big-wasps-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
'@leafygreen-ui/input-option': major
---

### API changes
- Renames `selected` prop to `checked` (this is done to avoid confusion with the `aria-selected` attribute, which is conditionally applied via the `highlighted` prop)
- `checked` applies the `aria-checked` attribute
- Note: `checked` _does not_ apply any styles. Any "checked" styles must be applied by the consuming component (this is consistent with previous behavior)
- Adds `preserveIconSpace` prop to `InputOptionContent` to determine whether menu items should preserve space for a left glyph, or left align all text content. Use this prop in menus where some items may or may not have icons/glyphs, in order to keep text across menu items aligned.
- Extends `AriaLabelPropsWithChildren` in `InputOptionProps`
TheSonOfThomp marked this conversation as resolved.
Show resolved Hide resolved
- [`AriaLabelPropsWithChildren`](../packages/a11y/src/AriaLabelProps.ts) allows a component to accept any of `aria-label`, `aria-labelledby` or `children` as sufficient text for screen-reader accessibility

### Styling changes

- Updates `InputOption` and `InputOptionContent` styles to use updated `color` and `spacing` tokens
- Exports `inputOptionClassName`, and `inputOptionContentClassName`.

#### Spacing overview
- block padding: 8px
- inline padding: 12px
- icon/text/chevron gap: 8px
- label & description font-size: 13px
- label & description line-height: 16px

#### Colors overview
- Left & right icon color: `color.[theme].icon.primary` tokens
- Label & Description: use default `Label` & `Description` colors from `typography`
- Background uses `color[theme].background.primary` tokens (including hover & focus states)
- Wedge uses `palette.blue.base` for all modes
- The `highlight` prop uses the `.focus` state color for Icon, Text & Background colors


### Internal updates

- Establishes internal `InputOptionContext` to track `disabled`, `highlighted`, & `checked` attributes.
5 changes: 5 additions & 0 deletions .changeset/shaggy-cheetahs-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/a11y': minor
---

Adds `AriaLabelPropsWithChildren` type that requires either `children`, or other `aria-label` attributes to be defined. Allows a component to accept any of `aria-label`, `aria-labelledby` or `children` as sufficient text for screen-reader accessibility
86 changes: 70 additions & 16 deletions packages/a11y/src/A11y.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { axe } from 'jest-axe';

import { renderHook } from '@leafygreen-ui/testing-lib';

import { AriaLabelProps, AriaLabelPropsWithLabel } from './AriaLabelProps';
import {
AriaLabelProps,
AriaLabelPropsWithChildren,
AriaLabelPropsWithLabel,
} from './AriaLabelProps';
import {
prefersReducedMotion,
useAccessibleForm,
Expand Down Expand Up @@ -123,50 +127,100 @@ describe('packages/a11y', () => {
/* eslint-disable jest/no-disabled-tests, jest/expect-expect, @typescript-eslint/no-unused-vars */
describe.skip('AriaLabelProps types', () => {
test('AriaLabelProps', () => {
// @ts-expect-error
const _1: AriaLabelProps = {};
const _2: AriaLabelProps = {
// @ts-expect-error - empty object not allowed
const empty: AriaLabelProps = {};
const aria_label: AriaLabelProps = {
'aria-label': 'some label',
};
const _3: AriaLabelProps = {
const labelledby: AriaLabelProps = {
'aria-labelledby': '#some-id',
};
const _4: AriaLabelProps = {
const both_aria: AriaLabelProps = {
'aria-label': 'some label',
'aria-labelledby': '#some-id',
};
[_1, _2, _3, _4]; // Avoid TS error
[empty, aria_label, labelledby, both_aria]; // Avoid TS error
});
test('AriaLabelPropsWithLabel', () => {
// @ts-expect-error
const _1: AriaLabelPropsWithLabel = {};
const _2: AriaLabelPropsWithLabel = {
const empty: AriaLabelPropsWithLabel = {};
const aria_label: AriaLabelPropsWithLabel = {
'aria-label': 'some label',
};
const _3: AriaLabelPropsWithLabel = {
const labelledby: AriaLabelPropsWithLabel = {
'aria-labelledby': '#some-id',
};
const _4: AriaLabelPropsWithLabel = {
const both_aria: AriaLabelPropsWithLabel = {
'aria-label': 'some label',
'aria-labelledby': '#some-id',
};
const _5: AriaLabelPropsWithLabel = {
const label_only: AriaLabelPropsWithLabel = {
label: 'some label',
};
const _6: AriaLabelPropsWithLabel = {
const label_and_aria: AriaLabelPropsWithLabel = {
label: 'some label',
'aria-label': 'some label',
};
const _7: AriaLabelPropsWithLabel = {
const label_and_labelledby: AriaLabelPropsWithLabel = {
label: 'some label',
'aria-labelledby': '#some-id',
};
const _8: AriaLabelPropsWithLabel = {
const all: AriaLabelPropsWithLabel = {
label: 'some label',
'aria-label': 'some label',
'aria-labelledby': '#some-id',
};
[_1, _2, _3, _4, _5, _6, _7, _8]; // Avoid TS error
[
empty,
aria_label,
labelledby,
both_aria,
label_only,
label_and_aria,
label_and_labelledby,
all,
]; // Avoid TS error
});
test('AriaLabelPropsWithChildren', () => {
// @ts-expect-error - empty object not allowed
const empty: AriaLabelPropsWithChildren = {};
const label: AriaLabelPropsWithChildren = {
'aria-label': 'some label',
};
const labelledby: AriaLabelPropsWithChildren = {
'aria-labelledby': '#some-id',
};
const both_aria: AriaLabelPropsWithChildren = {
'aria-label': 'some label',
'aria-labelledby': '#some-id',
};
const children: AriaLabelPropsWithChildren = {
children: 'some label',
};
const label_and_children: AriaLabelPropsWithChildren = {
children: 'some label',
'aria-label': 'some label',
};
const labelledby_and_children: AriaLabelPropsWithChildren = {
children: 'some label',
'aria-labelledby': '#some-id',
};
const all: AriaLabelPropsWithChildren = {
children: 'some label',
'aria-label': 'some label',
'aria-labelledby': '#some-id',
};

[
empty,
label,
labelledby,
both_aria,
children,
label_and_children,
labelledby_and_children,
all,
]; //
});
});
});
12 changes: 12 additions & 0 deletions packages/a11y/src/AriaLabelProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ export type AriaLabelPropsWithLabel =
*/
label: ReactNode;
} & Partial<AriaLabelProps>);

/**
* Conditionally requires {@link AriaLabelProps}
* if `children` is not provided
*/
export type AriaLabelPropsWithChildren =
bruugey marked this conversation as resolved.
Show resolved Hide resolved
| ({
children: ReactNode;
} & Partial<AriaLabelProps>)
| ({
children?: ReactNode | undefined;
} & AriaLabelProps);
7 changes: 4 additions & 3 deletions packages/a11y/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export {
type AriaLabelProps,
type AriaLabelPropsWithLabel,
export type {
AriaLabelProps,
AriaLabelPropsWithChildren,
AriaLabelPropsWithLabel,
} from './AriaLabelProps';
export { default as prefersReducedMotion } from './prefersReducedMotion';
export { default as useAccessibleForm } from './useAccessibleForm';
Expand Down
30 changes: 19 additions & 11 deletions packages/input-option/src/InputOption/InputOption.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable react/jsx-key */
import React from 'react';
import {
storybookArgTypes,
storybookExcludedControlParams,
StoryMetaType,
} from '@lg-tools/storybook-utils';
import { StoryFn } from '@storybook/react';
import { StoryFn, StoryObj } from '@storybook/react';

import Icon, { glyphs } from '@leafygreen-ui/icon';

Expand All @@ -15,7 +16,7 @@ import {

import { InputOption, type InputOptionProps } from '.';

const meta: StoryMetaType<typeof InputOption> = {
export default {
title: 'Components/InputOption',
component: InputOption,
parameters: {
Expand All @@ -31,17 +32,15 @@ const meta: StoryMetaType<typeof InputOption> = {
],
},
generate: {
storyNames: ['Generated', 'WithContent'],
combineArgs: {
darkMode: [false, true],
selected: [false, true],
isInteractive: [false, true],
showWedge: [false, true],
disabled: [false, true],
},
},
},
args: {
children: 'Some text',
showWedge: true,
},
argTypes: {
disabled: {
Expand All @@ -50,7 +49,7 @@ const meta: StoryMetaType<typeof InputOption> = {
highlighted: {
control: 'boolean',
},
selected: {
checked: {
control: 'boolean',
},
showWedge: {
Expand All @@ -69,9 +68,7 @@ const meta: StoryMetaType<typeof InputOption> = {
},
as: storybookArgTypes.as,
},
};

export default meta;
} satisfies StoryMetaType<typeof InputOption>;

export const LiveExample: StoryFn<
InputOptionProps & InputOptionContentProps
Expand All @@ -95,4 +92,15 @@ LiveExample.parameters = {
chromatic: { disableSnapshot: true },
};

export const Generated = () => {};
export const Generated = {
render: () => <></>,
parameters: {
generate: {
combineArgs: {
highlighted: [false, true],
checked: [false, true],
disabled: [false, true],
shaneeza marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
} satisfies StoryObj<typeof InputOption>;
Loading
Loading