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

434 feat make select option components #438

Merged
merged 4 commits into from
Sep 4, 2024
Merged
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
1 change: 1 addition & 0 deletions docs/app/components/code-builder/builder-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function BuilderForm(props: BuilderFormProps) {
<Show when={props.api[key].type === 'enum'}>
<Select
{...(props.api[key] as EnumResult)}
id={props.api[key].name}
onChange={handleSelectChange}
options={props.api[key].value as string[]}
value={selectedProps[key] as string}
Expand Down
5 changes: 5 additions & 0 deletions docs/app/components/code-builder/builder-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export default function BuilderLayout(
className={vstack({
justify: 'center',
mx: 'auto',
w: {
'@/sm': 'full',
'@/md': '1/2',
},
})}
>
{props.children}
Expand All @@ -61,6 +65,7 @@ export default function BuilderLayout(
position: 'sticky',
textStyle: 'h6',
top: '0',
zIndex: 'sticky',
})}
>
Preview Playground
Expand Down
27 changes: 6 additions & 21 deletions docs/app/components/code-builder/builder-select.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
import { type SelectHTMLAttributes } from 'react'
import type { EnumResult } from './helpers'
import { css } from '@cerberus/styled-system/css'
import { focusStates } from '@cerberus-design/panda-preset'
import { Select, type SelectProps, Option } from '@cerberus-design/react'

type BuilderSelectProps = Omit<EnumResult, 'value'> &
SelectHTMLAttributes<HTMLSelectElement> & {
SelectProps & {
options: string[]
}

export default function BuilderSelect(props: BuilderSelectProps) {
const { options, ...nativeProps } = props
return (
<select
{...nativeProps}
className={css({
border: '1px solid',
borderColor: 'action.border.initial',
color: 'page.text.initial',
h: '2.5rem',
pxi: '2',
rounded: 'sm',
...focusStates,
w: 'full',
})}
id={nativeProps.name}
>
<Select {...nativeProps} id={nativeProps.name}>
{options.map((choice) => (
<option key={choice} value={choice}>
<Option key={choice} value={choice}>
{choice}
</option>
</Option>
))}
</select>
</Select>
)
}
12 changes: 10 additions & 2 deletions docs/app/components/code-builder/builder-snippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { useCodeBuilder } from '@/app/context/code-builder'
import { useMemo, type PropsWithChildren } from 'react'
import { css } from '@cerberus/styled-system/css'

function isFormState(key: string) {
return ['disabled', 'required', 'readOnly', 'invalid'].includes(key)
}

function isChildContent(key: string) {
return ['text', 'helpText', 'label'].includes(key)
}

interface BuilderSnippetProps {
code: string
}
Expand All @@ -16,11 +24,11 @@ export default function BuilderSnippet(
const { selectedProps } = useCodeBuilder()
const code = useMemo(() => {
return props.code.replace(/{{([^}]+)}}/g, (_, key): string => {
if (key === 'text') {
if (isChildContent(key)) {
return (selectedProps[key as keyof typeof selectedProps] ||
'Add Text') as string
}
if (key === 'disabled') {
if (isFormState(key)) {
return `{${selectedProps[key as keyof typeof selectedProps] || 'false'}}`
}
return `"${selectedProps[key as keyof typeof selectedProps] || 'false'}"`
Expand Down
11 changes: 6 additions & 5 deletions docs/app/react/select/a11y.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ import OverviewList from '@/app/components/OverviewList'
## Use Cases

<OverviewList intro="Users should be able to:" rules={[
'Navigate to and activate a text field with assistive technology',
'Input information into the text field',
'Receive and understand supporting text and error messages',
'Navigate to and select interactive icons',
'Navigate to and activate a select field with assistive technology',
'Choose an item from the list of options',
'Receive and understand supporting select and error messages'
]} />

## Keyboard Navigation

| Keys | Actions |
| -------- | --------------------------------------------------------------- |
| Tab | Focus lands on (non-disabled) input |
| Enter | Opens the dropdown menu and selects the focused option |
| Esc | Closes the dropdown menu |

## Labeling Elements

If the UI text is correctly linked, assistive tech (such as a screenreader) will read the UI text followed by the component's role.

The accessibility label for a textfield is typically the same as the label for the textfield.
The accessibility label for a select field is typically the same as the label for the text field.
127 changes: 0 additions & 127 deletions docs/app/react/select/components/input-preview.tsx

This file was deleted.

Loading