From 78a1c6c1ed825ef293f0e38c41d45553d85ae870 Mon Sep 17 00:00:00 2001 From: Zeno Rocha Date: Fri, 16 Feb 2018 15:18:08 -0800 Subject: [PATCH] Makes Dropdown SSR compatible #66 --- packages/marble-dropdown/src/Dropdown.js | 7 ++++++- packages/marble-dropdown/test/Dropdown.node.js | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 packages/marble-dropdown/test/Dropdown.node.js diff --git a/packages/marble-dropdown/src/Dropdown.js b/packages/marble-dropdown/src/Dropdown.js index e9b6008..81357ae 100644 --- a/packages/marble-dropdown/src/Dropdown.js +++ b/packages/marble-dropdown/src/Dropdown.js @@ -1,4 +1,4 @@ -import {core, object} from 'metal'; +import {core, object, isServerSide} from 'metal'; import dom from 'metal-dom'; import {Align} from 'metal-position'; import Component from 'metal-component'; @@ -16,6 +16,11 @@ class Dropdown extends Component { */ attached() { super.attached(); + + if (isServerSide()) { + return; + } + this.eventHandler_.add( dom.on(document, 'click', this.handleDocClick_.bind(this)) ); diff --git a/packages/marble-dropdown/test/Dropdown.node.js b/packages/marble-dropdown/test/Dropdown.node.js new file mode 100644 index 0000000..6bebcb5 --- /dev/null +++ b/packages/marble-dropdown/test/Dropdown.node.js @@ -0,0 +1,13 @@ +/** + * @jest-environment node + */ + +import Component from 'metal-component'; +import Dropdown from '../src/Dropdown'; + +describe('Dropdown.node', () => { + it('should not fail on the server side', () => { + const dropdown = Component.renderToString(Dropdown); + expect(dropdown).not.toBeNull(); + }); +});