Skip to content

Commit

Permalink
fix: Resolves the inconsistency of the disabled focus state of the Se…
Browse files Browse the repository at this point in the history
…lect and Combobox

Co-authored-by: AqidaHaidari <42426077+AqidaHaidari@users.noreply.github.com>
  • Loading branch information
gitstart and AqidaHaidari committed Sep 12, 2023
1 parent 13ccb77 commit bff7726
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/primitives/src/components/Combobox/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ const ComboboxTrigger = React.forwardRef<ComboboxTriggerElement, TriggerProps>((
ref={forwardedRef}
data-disabled={context.disabled ? '' : undefined}
{...triggerProps} // Enable compatibility with native label or custom `Label` "click" for Safari:
onClick={composeEventHandlers(triggerProps.onClick, () => {
onClick={composeEventHandlers(triggerProps.onClick, (event) => {
// To prevent focus() calls from Slot, it causes unexpected focus states on UI
// ref: https://github.com/strapi/design-system/issues/1330
if (context.disabled) {
event.preventDefault();
return;
}

// Whilst browsers generally have no issue focusing the trigger when clicking
// on a label, Safari seems to struggle with the fact that there's no `onClick`.
// We force `focus` in this case. Note: this doesn't create any other side-effect
Expand All @@ -300,6 +307,13 @@ const ComboboxTrigger = React.forwardRef<ComboboxTriggerElement, TriggerProps>((
context.trigger?.focus();
})}
onPointerDown={composeEventHandlers(triggerProps.onPointerDown, (event) => {
// To prevent focus() calls from Slot, it causes unexpected focus states on UI
// ref: https://github.com/strapi/design-system/issues/1330
if (context.disabled) {
event.preventDefault();
return;
}

// prevent implicit pointer capture
// https://www.w3.org/TR/pointerevents3/#implicit-pointer-capture
const target = event.target as HTMLElement;
Expand Down

0 comments on commit bff7726

Please sign in to comment.