Skip to content
Open
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 .reports/embedded-react-sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,7 @@ function OffCycleReasonSelection(props: OffCycleReasonSelectionProps): JSX;
// @public
interface OffCycleReasonSelectionProps extends BaseComponentInterface<'Payroll.OffCycleReasonSelection'> {
companyId: string;
defaultReason?: OffCycleReason;
}

// @public
Expand Down
1 change: 1 addition & 0 deletions docs/reference/payroll/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ Props for the [OffCycleReasonSelection](#offcyclereasonselection) component.
| ------ | ------ | ------ |
| `companyId` | `string` | The associated company identifier. |
| `onEvent` | [`OnEventType`](../events.md#oneventtype)\<[`EventType`](../events.md#eventtype), `unknown`\> | Callback invoked each time the component emits an event — user interactions, successful API responses, step transitions, or errors. Receives the event type constant and an optional payload whose shape varies by event. See the [Event Handling guide](https://docs.gusto.com/embedded-payroll/docs/event-handling) and each component's event table for the full list of emitted events. |
| `defaultReason?` | [`OffCycleReason`](#offcyclereason) | Pre-selected reason rendered when the form mounts. Leave unset to render with no option selected. |
| `dictionary?` | `Record`\<`"en"`, [`DeepPartial`](../Translations/index.md#deeppartial)\<[`PayrollOffCycleReasonSelection`](../Translations/index.md#payrolloffcyclereasonselection)\>\> | Overrides for the component's i18n strings. Supply a partial object whose keys match the component's resource namespace — any omitted keys fall back to SDK defaults. See the [Translation guide](https://docs.gusto.com/embedded-payroll/docs/translation) for details. |

_Inherits `children`, `className`, `defaultValues`, `FallbackComponent`, `LoaderComponent` from [BaseComponentInterface](../blocks.md#basecomponentinterface)._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { fn } from 'storybook/test'
import { FormWrapper } from '../../../../.storybook/helpers/FormWrapper'
import { OffCycleReasonSelectionPresentation } from './OffCycleReasonSelectionPresentation'
import { OffCycleReasonSelection } from './OffCycleReasonSelection'
import { useI18n } from '@/i18n'

function I18nLoader({ children }: { children: React.ReactNode }) {
Expand Down Expand Up @@ -49,3 +51,7 @@ CorrectionSelected.decorators = [
</I18nLoader>
),
]

export const WithDefaultReason = () => (
<OffCycleReasonSelection companyId="mock-company-id" onEvent={fn()} defaultReason="bonus" />
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ describe('OffCycleReasonSelection', () => {
expect(radio).not.toBeChecked()
})
})

it('pre-selects the option matching defaultReason', async () => {
renderWithProviders(<OffCycleReasonSelection {...defaultProps} defaultReason="bonus" />)

await waitFor(() => {
expect(screen.getByLabelText('Bonus')).toBeInTheDocument()
})

expect(screen.getByLabelText('Bonus')).toBeChecked()
expect(screen.getByLabelText('Correction payment')).not.toBeChecked()
})
})

describe('selection behavior', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export function OffCycleReasonSelection(props: OffCycleReasonSelectionProps) {
)
}

function Root({ dictionary }: OffCycleReasonSelectionProps) {
function Root({ dictionary, defaultReason }: OffCycleReasonSelectionProps) {
useComponentDictionary('Payroll.OffCycleReasonSelection', dictionary)
useI18n('Payroll.OffCycleReasonSelection')

const { onEvent } = useBase()
const methods = useForm<{ reason: OffCycleReason | '' }>({
defaultValues: { reason: '' },
defaultValues: { reason: defaultReason ?? '' },
})

const handleReasonChange = useCallback(
Expand Down
2 changes: 2 additions & 0 deletions src/components/Payroll/OffCycleReasonSelection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ export interface SelectReasonPayload {
export interface OffCycleReasonSelectionProps extends BaseComponentInterface<'Payroll.OffCycleReasonSelection'> {
/** The associated company identifier. */
companyId: string
/** Pre-selected reason rendered when the form mounts. Leave unset to render with no option selected. */
defaultReason?: OffCycleReason
}
Loading