Skip to content
This repository was archived by the owner on Aug 2, 2024. It is now read-only.

Commit ae90dda

Browse files
committed
Use consts for above/below, add set/get for positioning
1 parent 71589e2 commit ae90dda

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

addon/components/polaris-popover.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { warn } from '@ember/debug';
66
import layout from '../templates/components/polaris-popover';
77

88
const { ViewUtils } = Ember;
9+
const ABOVE = 'above';
10+
const BELOW = 'below';
911

1012
/**
1113
* Polaris popover component.
@@ -39,9 +41,7 @@ export default Component.extend({
3941
* @type {string}
4042
* @default 'below'
4143
*/
42-
preferredPosition: computed(function() {
43-
return 'below';
44-
}),
44+
preferredPosition: BELOW,
4545

4646
/**
4747
* Show or hide the Popover
@@ -95,17 +95,29 @@ export default Component.extend({
9595
/*
9696
* Internal properties.
9797
*/
98-
verticalPosition: computed('preferredPosition', function() {
99-
let preferredPosition = this.get('preferredPosition');
98+
verticalPosition: computed('preferredPosition', {
99+
// If `preferredPosition` is set to `mostSpace`, the value
100+
// will be calculated and set when the user opens the popover.
101+
// The only allowed values are 'above' and 'below', so we
102+
// return null for anything other than those values and let
103+
// ember-basic-dropdown use its default value.
104+
get() {
105+
let preferredPosition = this.get('preferredPosition');
100106

101-
if (preferredPosition === 'above' || preferredPosition === 'below') {
102-
return preferredPosition;
103-
}
107+
if (preferredPosition === ABOVE || preferredPosition === BELOW) {
108+
return preferredPosition;
109+
}
104110

105-
// If set to `mostSpace`, the value will be calculated
106-
// and set when the user opens the popover.
111+
return null;
112+
},
107113

108-
return null;
114+
set(key, value) {
115+
if (value === ABOVE || value === BELOW) {
116+
return value;
117+
}
118+
119+
return null;
120+
}
109121
}),
110122

111123
triggerStyle: computed(function() {
@@ -137,7 +149,7 @@ export default Component.extend({
137149

138150
if (activators.length > 1) {
139151
warn('Multiple popover activators found. Defaulting to `preferredPosition` of `below`');
140-
return 'below';
152+
return BELOW;
141153
}
142154

143155
let [activator] = activators;
@@ -146,7 +158,7 @@ export default Component.extend({
146158
let bottomSpace = windowHeight - bottom;
147159

148160
// Use `below` if distance is equal
149-
return bottomSpace >= top ? 'below' : 'above';
161+
return bottomSpace >= top ? BELOW : ABOVE;
150162
},
151163

152164
actions: {

addon/templates/components/polaris-popover.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{#basic-dropdown
22
verticalPosition=verticalPosition
3-
onOpen=(action 'onOpen')
3+
onOpen=(action "onOpen")
44
as |dd|
55
}}
66
{{yield (hash

0 commit comments

Comments
 (0)