Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
feat(context-dialog): Simplifies overriding the maxWidth of the overl…
Browse files Browse the repository at this point in the history
…ay.You can now set the maxWidth as part of the DT_CONTEXT_DIALOG_CONFIG token and it will properly be reflected on the overlay.
  • Loading branch information
ffriedl89 authored and tomheller committed Nov 11, 2020
1 parent 960f078 commit 2c501b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
24 changes: 12 additions & 12 deletions libs/barista-components/context-dialog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class MyModule {}

## Inputs

| Name | Type | Default | Description |
| ------------------- | ---------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------- |
| `tabIndex` | `number` | `0` | Gets and sets the tabIndex on the context dialog. Inherited by mixinTabIndex. |
| `disabled` | `boolean` | `false` | Gets and sets the disabled property on the context dialog. Inherited by mixinDisabled. |
| `aria-label` | `string` | `undefined` | ARIA label of the context dialog trigger button. |
| `aria-labelledby` | `string` | `undefined` | ARIA reference to a label describing the context-dialog. |
| `ariaLabelClose` | `string` | | ARIA label of the context dialog close button. |
| `overlayPanelClass` | `string | string[] | Set<string> | { [key: string]: any }` | | Custom css classes to add to the overlay panel element. Can be used to scope styling within the overlay |
| Name | Type | Default | Description |
| ------------------- | --------- | ----------- | -------------------------------------------------------------------------------------- |
| `tabIndex` | `number` | `0` | Gets and sets the tabIndex on the context dialog. Inherited by mixinTabIndex. |
| `disabled` | `boolean` | `false` | Gets and sets the disabled property on the context dialog. Inherited by mixinDisabled. |
| `aria-label` | `string` | `undefined` | ARIA label of the context dialog trigger button. |
| `aria-labelledby` | `string` | `undefined` | ARIA reference to a label describing the context-dialog. |
| `ariaLabelClose` | `string` | | ARIA label of the context dialog close button. |
| `overlayPanelClass` | `string | string[] | Set<string> | { [key: string]: any }` | | Custom css classes to add to the overlay panel element. Can be used to scope styling within the overlay |

To make our components accessible it is obligatory to provide either an
`aria-label` or `aria-labelledby`.
Expand All @@ -52,10 +52,10 @@ To make our components accessible it is obligatory to provide either an

## Configuration options

If your use case requires a different configuration of the overlay, it can be
configured using the `DT_CONTEXT_DIALOG_CONFIG` injection token. Only the
settings you provide will be overwritten, the others will fall back to the
default configuration.
If your use case requires a different configuration of the overlay e.g. setting
your own maxWidth, it can be configured using the `DT_CONTEXT_DIALOG_CONFIG`
injection token. Only the settings you provide will be overwritten, the others
will fall back to the default configuration.

## Accessibility

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@import '../../core/src/style/variables';

$panel-padding: 12px;
$dialog-max-width: 328px;
$context-dialog-panel-padding: 12px;
$panel-padding-btn: 38px;
$context-dialog-top-header-padding: 8px;
Expand All @@ -19,7 +18,6 @@ $context-dialog-top-header-padding: 8px;
position: relative;
transform-origin: top right;
color: #ffffff;
max-width: $dialog-max-width;
max-height: 90vh;
display: flex;
flex-direction: column;
Expand Down
5 changes: 4 additions & 1 deletion libs/barista-components/context-dialog/src/context-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export const DT_CONTEXT_DIALOG_CONFIG = new InjectionToken<OverlayConfig>(
'dt-context-dialog-config',
);

const DT_CONTEXT_DIALOG_DEFAULT_MAX_WIDTH = 328;

@Component({
selector: 'dt-context-dialog',
templateUrl: 'context-dialog.html',
Expand Down Expand Up @@ -316,11 +318,12 @@ export class DtContextDialog
.withViewportMargin(0)
.withLockedPosition(false);

const defaultConfig = {
const defaultConfig: OverlayConfig = {
positionStrategy,
scrollStrategy: this._overlay.scrollStrategies.block(),
backdropClass: 'cdk-overlay-transparent-backdrop',
hasBackdrop: true,
maxWidth: DT_CONTEXT_DIALOG_DEFAULT_MAX_WIDTH,
};

const overlayConfig = this._userConfig
Expand Down

0 comments on commit 2c501b6

Please sign in to comment.