Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

feat(modal): core modal #4479

Merged
merged 1 commit into from Apr 30, 2020
Merged

Conversation

jeeyun
Copy link
Contributor

@jeeyun jeeyun commented Apr 16, 2020

Signed-off-by: Jeeyun Lim jeeyun.lim@gmail.com

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • If applicable, have a visual design approval

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • clarity.design website / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #3953

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@jeeyun jeeyun self-assigned this Apr 16, 2020
src/clr-core/modal/modal.stories.ts Show resolved Hide resolved
src/clr-core/styles/utils/_a11y.scss Outdated Show resolved Hide resolved
src/clr-core/styles/utils/_close.scss Outdated Show resolved Hide resolved
src/clr-core/styles/utils/_close.scss Outdated Show resolved Hide resolved
src/clr-core/modal/modal.element.ts Show resolved Hide resolved
src/clr-core/internal/base/focus-trap.base.ts Show resolved Hide resolved
src/clr-core/modal/modal.element.scss Outdated Show resolved Hide resolved
src/clr-core/modal/modal.element.scss Outdated Show resolved Hide resolved
src/clr-core/modal/modal.element.scss Outdated Show resolved Hide resolved
src/clr-core/modal/modal-actions.element.scss Outdated Show resolved Hide resolved
src/clr-core/styles/utils/_a11y.scss Outdated Show resolved Hide resolved
src/clr-core/styles/utils/_a11y.scss Outdated Show resolved Hide resolved
src/clr-core/styles/layout/_layout.scss Outdated Show resolved Hide resolved
src/clr-core/modal/package.json Outdated Show resolved Hide resolved
src/clr-core/modal/modal.stories.ts Outdated Show resolved Hide resolved
src/clr-core/alert/alert.stories.ts Outdated Show resolved Hide resolved
src/clr-core/internal/base/focus-trap.base.ts Outdated Show resolved Hide resolved
src/clr-core/modal/modal-actions.element.scss Outdated Show resolved Hide resolved
src/clr-core/modal/modal.element.scss Outdated Show resolved Hide resolved
src/clr-core/modal/modal.element.ts Outdated Show resolved Hide resolved
return;
}

if ($event.target && this.hostElement) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on this?

src/clr-core/internal/utils/dom.ts Show resolved Hide resolved
src/clr-core/modal/modal.element.scss Outdated Show resolved Hide resolved
src/clr-core/modal/modal.element.ts Show resolved Hide resolved
</div>
<div class="clr-sr-only">${CommonStringsService.keys.modalContentEnd}</div>
</div>
<div class="modal-backdrop" aria-hidden="true"></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts here?

src/clr-core/styles/utils/_close.scss Show resolved Hide resolved
src/clr-core/styles/layout/_layout.scss Outdated Show resolved Hide resolved
src/clr-core/styles/utils/_close.scss Show resolved Hide resolved
return;
}

if ($event.target && this.hostElement) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A function with lots of params can be a hint that a data structure is needed. You could apply this here:

interface FocusTrapElement extends HTMLElement {
  topReboundElement: HTMLElement;
  bottomReboundElement: HTMLElement;
}

export function focusElementIfInCurrentFocusTrapElement(focusedElement: HTMLElement, focusTrapElement: FocusTrapElement) {
  if (FocusTrapTracker.getCurrent() === focusTrapElement && elementIsOutsideFocusTrapElement(focusedElement, focusTrapElement)) {
    focusTrapElement.focus();
  }
}

export function elementIsOutsideFocusTrapElement(focusedElement: HTMLElement, focusTrapElement: FocusTrapElement) {
  return !focusTrapElement.contains(focusedElement) ||
  focusedElement === focusTrapElement.topReboundElement ||
  focusedElement === focusTrapElement.bottomReboundElement;
}

export class CdsBaseFocusTrap extends LitElement {
  topReboundElement: HTMLElement;
  bottomReboundElement: HTMLElement;

  ...
  protected onFocusIn(event: FocusEvent) {
    focusElementIfInCurrentFocusTrapElement(event.target as HTMLElement, this);
  }
}

src/clr-core/internal/base/focus-trap.base.ts Outdated Show resolved Hide resolved
src/clr-core/internal/base/focus-trap.base.ts Outdated Show resolved Hide resolved
src/clr-core/internal/base/focus-trap.base.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@mathisscott mathisscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of minor requests. Approving pre-emptively as neither are major issues.

src/clr-core/internal/base/focus-trap.base.spec.ts Outdated Show resolved Hide resolved
src/clr-core/internal/base/focus-trap.base.ts Show resolved Hide resolved
src/clr-core/internal/utils/dom.ts Outdated Show resolved Hide resolved
src/clr-core/internal/base/focus-trap.base.ts Outdated Show resolved Hide resolved
src/clr-core/modal/modal.stories.ts Outdated Show resolved Hide resolved
Signed-off-by: Jeeyun Lim <jeeyun.lim@gmail.com>
@jeeyun jeeyun merged commit 428dea1 into vmware-archive:master Apr 30, 2020
@jeeyun jeeyun deleted the topic/core-modal branch May 1, 2020 02:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants