-
Notifications
You must be signed in to change notification settings - Fork 52
Add schedule event type filters #393
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { getLiteral } from '../../common/i18n' | ||
| import TYPES from '../event-type-chip/types' | ||
|
|
||
| const EventFilter = ({ eventTypes, selectedType, onSelectType, totalEvents }) => { | ||
| if (eventTypes.length === 0) return null | ||
|
|
||
| return ( | ||
| <div className="event-filter" aria-label={getLiteral('schedule:filter-label')}> | ||
| <span className="event-filter__label"> | ||
| {getLiteral('schedule:filter-label')} | ||
| </span> | ||
| <div className="event-filter__options"> | ||
| <button | ||
| type="button" | ||
| className="event-filter__option" | ||
| data-active={selectedType === 'all' ? true : undefined} | ||
| aria-pressed={selectedType === 'all'} | ||
| onClick={() => onSelectType('all')} | ||
| > | ||
| {getLiteral('schedule:filter-all')} | ||
| <span className="event-filter__count">{totalEvents}</span> | ||
| </button> | ||
| {eventTypes.map((type) => ( | ||
| <button | ||
| key={type.value} | ||
| type="button" | ||
| className="event-filter__option" | ||
| data-active={selectedType === type.value ? true : undefined} | ||
| aria-pressed={selectedType === type.value} | ||
| onClick={() => onSelectType(type.value)} | ||
| > | ||
| {TYPES[type.value].label} | ||
| <span className="event-filter__count">{type.count}</span> | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default EventFilter | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| .event-filter { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: spacing(1); | ||
| margin-top: spacing(3); | ||
|
|
||
| &__label { | ||
| @extend %subtitle-2; | ||
| color: $white-80; | ||
| } | ||
|
|
||
| &__options { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| gap: spacing(1); | ||
| } | ||
|
|
||
| &__option { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: spacing(1); | ||
| padding: spacing(1) spacing(1.5); | ||
| border: 1px solid $white-40; | ||
| border-radius: 27px; | ||
| background: transparent; | ||
| color: $white-80; | ||
| @extend %subtitle-2; | ||
| cursor: pointer; | ||
| transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease; | ||
|
|
||
| &:hover, | ||
| &:focus-visible, | ||
| &[data-active] { | ||
| background: $white; | ||
| border-color: $white; | ||
| color: $purple; | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| outline: 2px solid $green; | ||
| outline-offset: 2px; | ||
| } | ||
| } | ||
|
|
||
| &__count { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| min-width: 1.5em; | ||
| padding: 0 spacing(0.5); | ||
| border-radius: 999px; | ||
| background: $white-20; | ||
| font-size: 0.75rem; | ||
| } | ||
|
|
||
| &__option[data-active] &__count, | ||
| &__option:hover &__count, | ||
| &__option:focus-visible &__count { | ||
| background: rgba($purple, 0.12); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { fireEvent, render, screen } from '@testing-library/react' | ||
|
|
||
| import EventsList from '../components/events-list/EventsList' | ||
|
|
||
| const baseEvent = { | ||
| formattedDate: { | ||
| date: 'May 14', | ||
| startTime: { utc: '7:00 pm', pt: '12:00 pm' }, | ||
| endTime: { utc: '8:00 pm', pt: '1:00 pm' }, | ||
| timeDisplay: 'specific', | ||
| }, | ||
|
Comment on lines
+5
to
+11
|
||
| language: 'English', | ||
| location: 'Virtual', | ||
| userName: 'Maintainer Month', | ||
| userLink: 'https://github.com/github/maintainermonth', | ||
| link: '/schedule/test-event', | ||
| linkUrl: 'https://github.com/github/maintainermonth', | ||
| metaDesc: 'A test event.', | ||
| } | ||
|
|
||
| const events = [ | ||
| { | ||
| ...baseEvent, | ||
| slug: 'meetup-event', | ||
| title: 'Maintainer meetup', | ||
| type: 'meetup', | ||
| }, | ||
| { | ||
| ...baseEvent, | ||
| slug: 'workshop-event', | ||
| title: 'Maintainer workshop', | ||
| type: 'workshop', | ||
| }, | ||
| ] | ||
|
|
||
| describe('EventsList filters', () => { | ||
| test('filters schedule cards by event type and restores all events', () => { | ||
| render(<EventsList events={events} />) | ||
|
|
||
| expect(screen.getByRole('button', { name: /All event types 2/i })).toBeTruthy() | ||
| expect(screen.getByRole('button', { name: /Meetup 1/i })).toBeTruthy() | ||
| expect(screen.getByRole('button', { name: /Workshop 1/i })).toBeTruthy() | ||
| expect(screen.getByText('Maintainer meetup')).toBeTruthy() | ||
| expect(screen.getByText('Maintainer workshop')).toBeTruthy() | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: /Meetup 1/i })) | ||
|
|
||
| expect(screen.getByText('Maintainer meetup')).toBeTruthy() | ||
| expect(screen.queryByText('Maintainer workshop')).toBeNull() | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: /Workshop 1/i })) | ||
|
|
||
| expect(screen.queryByText('Maintainer meetup')).toBeNull() | ||
| expect(screen.getByText('Maintainer workshop')).toBeTruthy() | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: /All event types 2/i })) | ||
|
|
||
| expect(screen.getByText('Maintainer meetup')).toBeTruthy() | ||
| expect(screen.getByText('Maintainer workshop')).toBeTruthy() | ||
| }) | ||
| }) | ||
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.
aria-labelon a plain<div>typically isn’t exposed unless the element has an explicit/implicit ARIA role, so the filter group may be unlabeled for assistive tech. Consider usingrole="group"witharia-labelledbypointing at the visible label, or use a<fieldset>+<legend>so the control group has proper semantics.