Skip to content

Commit 5eda2b2

Browse files
Merge pull request #4395 from Shopify/jhen__update_checkbox_docs_to_support_label_slot
Update checkbox docs to support label slot
2 parents c0ca438 + f1b3896 commit 5eda2b2

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

.changeset/checkbox-rich-label.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/ui-extensions': minor
3+
---
4+
5+
The `label` prop on the checkout and customer-account `s-checkbox` component now accepts a label as a slot in addition to a plain string, label slots can include only plain text and s-links.

packages/ui-extensions/src/surfaces/checkout/components/Checkbox.d.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,49 @@
1111
import type {CheckboxProps$1} from './components-shared.d.ts';
1212

1313
/**
14-
* Used when an element does not have children.
14+
* The base properties for elements that don't have children, providing essential attributes like keys and refs for component management.
1515
*/
1616
export interface BaseElementProps<TClass = HTMLElement> {
17+
/**
18+
* A unique identifier for this element within its parent. This is used by the rendering engine for efficient reconciliation when lists change.
19+
*/
1720
key?: preact.Key;
21+
/**
22+
* A reference to the underlying DOM element, typically created using `useRef()`. This allows you to access and manipulate the DOM element directly in your component logic.
23+
*/
1824
ref?: preact.Ref<TClass>;
25+
/**
26+
* Assigns the element to a named slot in a parent component that uses slot-based composition patterns.
27+
*/
1928
slot?: Lowercase<string>;
2029
}
2130
/**
2231
* An event type that narrows the `currentTarget` to the specific HTML element associated with the custom element tag. This provides type-safe event handling in callback listeners.
32+
* @publicDocs
2333
*/
2434
export type CallbackEvent<TTagName extends keyof HTMLElementTagNameMap, TEvent extends Event = Event> = TEvent & {
2535
currentTarget: HTMLElementTagNameMap[TTagName];
2636
};
2737
/**
2838
* A typed event listener for custom element events. The listener receives a `CallbackEvent` with the correct `currentTarget` type for the associated custom element tag.
39+
* @publicDocs
2940
*/
3041
export type CallbackEventListener<TTagName extends keyof HTMLElementTagNameMap, TData = object> = (EventListener & {
3142
(event: CallbackEvent<TTagName, Event> & TData): void;
3243
}) | null;
3344

3445
declare const tagName = "s-checkbox";
3546
/** @publicDocs */
36-
export interface CheckboxElementProps extends Pick<CheckboxProps$1, 'accessibilityLabel' | 'checked' | 'command' | 'commandFor' | 'defaultChecked' | 'disabled' | 'error' | 'id' | 'label' | 'name' | 'required' | 'value'> {
47+
export interface CheckboxElementProps extends Pick<CheckboxProps$1, 'accessibilityLabel' | 'checked' | 'command' | 'commandFor' | 'defaultChecked' | 'disabled' | 'error' | 'id' | 'name' | 'required' | 'value'> {
3748
command?: Extract<CheckboxProps$1['command'], '--auto' | '--show' | '--hide' | '--toggle'>;
49+
/**
50+
* The visual content to use as the control label. Use a string to provide a simple text label displayed to the user.
51+
*
52+
* If a `label` slot is also provided, the slot content takes precedence. [Learn more about slots](/docs/api/{API_NAME}/{API_VERSION}/web-components/forms/checkbox#slots-propertydetail-label).
53+
*/
54+
label?: string;
3855
}
56+
/** @publicDocs */
3957
export interface CheckboxEvents extends Pick<CheckboxProps$1, 'onChange'> {
4058
}
4159
/** @publicDocs */
@@ -47,9 +65,20 @@ export interface CheckboxElementEvents {
4765
*/
4866
change?: CallbackEventListener<typeof tagName>;
4967
}
68+
/** @publicDocs */
5069
export interface CheckboxElement extends CheckboxElementProps, Omit<HTMLElement, 'id' | 'onchange'> {
5170
onchange: CheckboxEvents['onChange'];
5271
}
72+
/** @publicDocs */
73+
export interface CheckboxElementSlots {
74+
/**
75+
* The visual content to use as the control label.
76+
*
77+
* Use an `HTMLElement` as a rich control label composed of elements. Only an `s-text` element is supported with plain text and `s-link` as its only allowed children. Any other elements are stripped while preserving their text content.
78+
*/
79+
label?: HTMLElement;
80+
}
81+
/** @publicDocs */
5382
export interface CheckboxProps extends CheckboxElementProps, CheckboxEvents {
5483
}
5584
declare global {
@@ -65,4 +94,4 @@ declare module 'preact' {
6594
}
6695
}
6796

68-
export type { CheckboxElement, CheckboxElementEvents, CheckboxElementProps, CheckboxEvents, CheckboxProps };
97+
export type { CheckboxElement, CheckboxElementEvents, CheckboxElementProps, CheckboxElementSlots, CheckboxEvents, CheckboxProps };

packages/ui-extensions/src/surfaces/checkout/components/Checkbox/Checkbox.doc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {createComponentDoc} from '../../../../docs/shared/component-definitions'
55

66
const data: ReferenceEntityTemplateSchema = createComponentDoc({
77
...sharedContent,
8-
definitions: {properties: true, events: true},
8+
definitions: {properties: true, events: true, slots: true},
99
});
1010

1111
export default data;

0 commit comments

Comments
 (0)