diff --git a/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx b/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx index 9aa4e3e..a72aa28 100644 --- a/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx +++ b/apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx @@ -152,6 +152,11 @@ export default function RecipeCard({ size="sm" aria-pressed={saved} onClick={handleSaveButtonClick} + aria-label={ + saved + ? `Remove ${title} from My Cookbook` + : `Save ${title} to My Cookbook` + } > { }); const saveButton = screen.getByRole('button', { - name: 'Save', + name: /^Save .* to My Cookbook$/, }); await user.tab(); @@ -97,7 +97,7 @@ describe('RecipeCard', () => { }); const saveButton = screen.getByRole('button', { - name: 'Save', + name: /^Save .* to My Cookbook$/, }); expect(saveButton.getAttribute('aria-pressed')).toBe('false'); @@ -121,7 +121,7 @@ describe('RecipeCard', () => { }); const savedButton = screen.getByRole('button', { - name: 'Saved', + name: /^Remove .* from My Cookbook$/, }); expect(savedButton.getAttribute('aria-pressed')).toBe('true'); @@ -156,7 +156,7 @@ describe('RecipeCard', () => { await user.click( screen.getByRole('button', { - name: 'Saved', + name: /^Remove .* from My Cookbook$/, }), ); @@ -174,13 +174,13 @@ describe('RecipeCard', () => { expect( screen.queryByRole('button', { - name: 'Save', + name: /^Save .* to My Cookbook$/, }), ).toBeNull(); expect( screen.queryByRole('button', { - name: 'Saved', + name: /^Remove .* from My Cookbook$/, }), ).toBeNull(); }); @@ -201,7 +201,7 @@ describe('RecipeCard', () => { expect( screen.queryByRole('button', { - name: 'Saved', + name: /^Remove .* from My Cookbook$/, }), ).toBeNull(); }); diff --git a/apps/web/src/components/ui/Select/Select.css b/apps/web/src/components/ui/Select/Select.css index 9a409b2..dee784e 100644 --- a/apps/web/src/components/ui/Select/Select.css +++ b/apps/web/src/components/ui/Select/Select.css @@ -82,6 +82,12 @@ box-shadow var(--duration-fast) var(--ease-standard); } + .select__control--with-leading-icon { + padding-inline-start: calc( + var(--space-3) + var(--icon-size-sm) + var(--space-2) + ); + } + .select--full .select__control { width: 100%; } @@ -118,6 +124,24 @@ cursor: not-allowed; } + /* Leading icon */ + + .select__leading-icon { + position: absolute; + z-index: 1; + top: 50%; + left: var(--space-3); + + width: var(--icon-size-sm); + height: var(--icon-size-sm); + + color: var(--color-icon-secondary); + + pointer-events: none; + + transform: translateY(-50%); + } + /* Chevron */ .select__icon { diff --git a/apps/web/src/components/ui/Select/Select.tsx b/apps/web/src/components/ui/Select/Select.tsx index dbaa696..99bfa95 100644 --- a/apps/web/src/components/ui/Select/Select.tsx +++ b/apps/web/src/components/ui/Select/Select.tsx @@ -1,6 +1,8 @@ -import type { ComponentPropsWithRef, ReactNode } from 'react'; +import type { ComponentPropsWithRef, ComponentType, ReactNode } from 'react'; import { ChevronDownIcon } from '../../../icons/navigation'; +import type { IconProps as SvgIconProps } from '../../../icons/types'; + import { Icon } from '../Icon/Icon'; import { FieldError, FieldHelp, RequiredMarker } from '../internal/FieldText'; import { useFieldA11y } from '../internal/fieldA11y'; @@ -13,6 +15,8 @@ export type SelectProps = Omit< 'size' | 'width' > & { label: ReactNode; + labelVisuallyHidden?: boolean; + leadingIcon?: ComponentType; helpText?: ReactNode; error?: ReactNode; children: ReactNode; @@ -21,6 +25,8 @@ export type SelectProps = Omit< function Select({ label, + labelVisuallyHidden = false, + leadingIcon: LeadingIcon, helpText, error, children, @@ -40,8 +46,10 @@ function Select({ }); const wrapperClasses = ['select', `select--${width}`].join(' '); + const selectClasses = [ 'select__control', + LeadingIcon && 'select__control--with-leading-icon', error && 'select__control--error', className, ] @@ -50,12 +58,27 @@ function Select({ return (
-