Repository navigation
chore: Add inline label to control group #5110
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
Open
jperals
wants to merge
22
commits into
main
Choose a base branch
from
dev-v3-jotresse-control-group-label
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4c6be35
feat: Add inlineLabelText to internal control group
jperals d8837b5
fix: Keep control group label above focus rings and below dropdowns
jperals c02d7e0
test: Add control group inline label dev page
jperals 7fadbbe
test: Lengthen control group dropdowns on labels dev page
jperals 9b94699
Minor refactor
jperals 3a67d27
chore: Dedupe control group dev page fixtures
jperals bb6b761
chore: Add test ids to grouped select and multiselect on labels page
jperals 97cf027
chore: Add autosuggest- and input-led grouped controls to labels page
jperals 4b628cf
chore: Add description, focus target, and direction toggle to labels …
jperals 32304a2
fix: Clear inline-token overlap on control group label
jperals c0b2485
Raise inline label uncoditionally to prevent it overlapping with inli…
jperals cd23767
Refine comment
jperals f9cfecc
Refine comment
jperals 6e7b034
Add standalone select at the top of the page
jperals e1238f5
Simplify subtitle
jperals 41adb31
fix: Portal grouped control dropdowns
jperals 87437b1
test: Assert grouped controls portal their dropdowns
jperals 1ab5cb2
Fix duplicated attributes
jperals 71b46af
chore: Provide default i18n on control group labels page
jperals 0146db3
test: Add internal control group findInlineLabel test util
jperals e495ca6
Update selector snapshots
jperals 014ffb8
Merge branch 'main' into dev-v3-jotresse-control-group-label
jperals File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,57 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import FormField from '~components/form-field'; | ||
| import { InternalControlGroupProps } from '~components/internal/components/control-group'; | ||
| import { MultiselectProps } from '~components/multiselect'; | ||
| import RadioGroup from '~components/radio-group'; | ||
| import { SelectProps } from '~components/select'; | ||
|
|
||
| import { useAppContext } from '../app/app-context'; | ||
|
|
||
| export const noop = () => { | ||
| /* empty handler to suppress controlled-component warnings */ | ||
| }; | ||
|
|
||
| export const operators: SelectProps.Option[] = [ | ||
| { value: '=', label: '=' }, | ||
| { value: '!=', label: '!=' }, | ||
| ]; | ||
|
|
||
| export const multiOptions: MultiselectProps.Option[] = [ | ||
| { value: '1', label: 'Option 1' }, | ||
| { value: '2', label: 'Option 2' }, | ||
| ]; | ||
|
|
||
| export const enteredTextLabel = (value: string) => `Use: ${value}`; | ||
|
|
||
| export type Direction = NonNullable<InternalControlGroupProps['direction']>; | ||
|
|
||
| export function useControlGroupDirection() { | ||
| const { urlParams, setUrlParams } = useAppContext<'controlGroupDirection'>(); // The name `direction` is already taken for the LTR/RTL URL parameter | ||
| const direction: Direction = urlParams.controlGroupDirection === 'vertical' ? 'vertical' : 'horizontal'; | ||
| const setDirection = (value: Direction) => setUrlParams({ controlGroupDirection: value }); | ||
| return { direction, setDirection }; | ||
| } | ||
|
|
||
| export function DirectionSettings({ | ||
| direction, | ||
| setDirection, | ||
| }: { | ||
| direction: Direction; | ||
| setDirection: (value: Direction) => void; | ||
| }) { | ||
| return ( | ||
| <FormField label="Direction"> | ||
| <RadioGroup | ||
| value={direction} | ||
| onChange={({ detail }) => setDirection(detail.value as Direction)} | ||
| items={[ | ||
| { value: 'horizontal', label: 'Horizontal' }, | ||
| { value: 'vertical', label: 'Vertical' }, | ||
| ]} | ||
| /> | ||
| </FormField> | ||
| ); | ||
| } | ||
This file contains hidden or 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,124 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React from 'react'; | ||
|
|
||
| import { SpaceBetween } from '~components'; | ||
| import Autosuggest, { AutosuggestProps } from '~components/autosuggest'; | ||
| import Input from '~components/input'; | ||
| import ControlGroup from '~components/internal/components/control-group'; | ||
| import Multiselect, { MultiselectProps } from '~components/multiselect'; | ||
| import Select, { SelectProps } from '~components/select'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
| import FocusTarget from '../common/focus-target'; | ||
| import { DirectionSettings, enteredTextLabel, multiOptions, noop, operators, useControlGroupDirection } from './common'; | ||
|
|
||
| const suggestions: AutosuggestProps.Option[] = Array.from({ length: 20 }, (_, i) => ({ | ||
| value: `Metric ${i + 1}`, | ||
| })); | ||
|
|
||
| // Long option lists so the control groups' open dropdowns extend far enough down to overlap the standalone controls below, | ||
| // to test that dropdowns are rendered over labels and not the other way around. | ||
| const longOperators: SelectProps.Option[] = Array.from({ length: 20 }, (_, i) => ({ | ||
| value: `op-${i + 1}`, | ||
| label: `Operator ${i + 1}`, | ||
| })); | ||
|
|
||
| const longMultiOptions: MultiselectProps.Option[] = Array.from({ length: 20 }, (_, i) => ({ | ||
| value: `${i + 1}`, | ||
| label: `Option ${i + 1}`, | ||
| })); | ||
|
|
||
| export default function ControlGroupLabels() { | ||
| const { direction, setDirection } = useControlGroupDirection(); | ||
|
|
||
| return ( | ||
| <SimplePage | ||
| title="Control group labels" | ||
| subtitle="Labels should be displayed above focus rings but below dropdowns." | ||
| settings={<DirectionSettings direction={direction} setDirection={setDirection} />} | ||
| i18n={{}} | ||
| screenshotArea={{}} | ||
| > | ||
| <FocusTarget /> | ||
| <SpaceBetween size="l"> | ||
| <Select | ||
| data-testid="standalone-select" | ||
| inlineLabelText="Namespace" | ||
| ariaLabel="Namespace" | ||
| selectedOption={longOperators[0]} | ||
| options={longOperators} | ||
| onChange={noop} | ||
| /> | ||
| <ControlGroup inlineLabelText="Filter by metric" direction={direction}> | ||
| <Select | ||
| data-testid="grouped-select" | ||
| ariaLabel="Operator" | ||
| selectedOption={longOperators[0]} | ||
| options={longOperators} | ||
| onChange={noop} | ||
| /> | ||
| <Input ariaLabel="Value" value="service" onChange={noop} /> | ||
| </ControlGroup> | ||
|
|
||
| <ControlGroup inlineLabelText="Threshold" direction={direction}> | ||
| <Multiselect | ||
| data-testid="grouped-multiselect" | ||
| ariaLabel="Labels" | ||
| inlineTokens={true} | ||
| selectedOptions={[longMultiOptions[0]]} | ||
| options={longMultiOptions} | ||
| onChange={noop} | ||
| /> | ||
| <Autosuggest | ||
| ariaLabel="Metric" | ||
| value="" | ||
| onChange={noop} | ||
| options={suggestions} | ||
| enteredTextLabel={enteredTextLabel} | ||
| /> | ||
| </ControlGroup> | ||
|
|
||
| <ControlGroup inlineLabelText="Metric name" direction={direction}> | ||
| <Autosuggest | ||
| data-testid="grouped-autosuggest" | ||
| ariaLabel="Metric" | ||
| value="CPU" | ||
| onChange={noop} | ||
| options={suggestions} | ||
| enteredTextLabel={enteredTextLabel} | ||
| /> | ||
| <Select ariaLabel="Operator" selectedOption={longOperators[0]} options={longOperators} onChange={noop} /> | ||
| </ControlGroup> | ||
|
|
||
| <ControlGroup inlineLabelText="Service" direction={direction}> | ||
| <Input data-testid="grouped-input" ariaLabel="Value" value="service" onChange={noop} /> | ||
| <Autosuggest | ||
| ariaLabel="Metric" | ||
| value="" | ||
| onChange={noop} | ||
| options={suggestions} | ||
| enteredTextLabel={enteredTextLabel} | ||
| /> | ||
| </ControlGroup> | ||
|
|
||
| <Input inlineLabelText="Service name" ariaLabel="Service name" value="service" onChange={noop} /> | ||
| <Select | ||
| inlineLabelText="Operator" | ||
| ariaLabel="Operator" | ||
| selectedOption={operators[0]} | ||
| options={operators} | ||
| onChange={noop} | ||
| /> | ||
| <Multiselect | ||
| inlineLabelText="Labels" | ||
| ariaLabel="Labels" | ||
| inlineTokens={true} | ||
| selectedOptions={[multiOptions[0]]} | ||
| options={multiOptions} | ||
| onChange={noop} | ||
| /> | ||
| </SpaceBetween> | ||
| </SimplePage> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parts extracted from
pages/control-group/permutations.page.tsxfor reuse