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

Commit

Permalink
Makes Datatable SSR compatible #66
Browse files Browse the repository at this point in the history
  • Loading branch information
zenorocha committed Feb 17, 2018
1 parent 2a144c2 commit 059dc5c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/marble-datatable/src/Datatable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import core from 'metal';
import {core, isServerSide} from 'metal';
import dom from 'metal-dom';
import templates from './Datatable.soy.js';
import Component from 'metal-component';
Expand All @@ -7,6 +7,19 @@ import Soy from 'metal-soy';
import UA from 'metal-useragent';

class Datatable extends Component {
/**
* @inheritDoc
*/
attached() {
if (isServerSide()) {
return;
}

this.keyboardFocusManager_ = new KeyboardFocusManager(this, 'td,th')
.setFocusHandler(this.handleNextFocus_.bind(this))
.start();
}

/**
* Visits array items and asserts that it only contains one literal type.
* @param {array} value
Expand Down Expand Up @@ -38,15 +51,6 @@ class Datatable extends Component {
}
}

/**
* @inheritDoc
*/
attached() {
this.keyboardFocusManager_ = new KeyboardFocusManager(this, 'td,th')
.setFocusHandler(this.handleNextFocus_.bind(this))
.start();
}

/**
* Builds a ref with for the given row and column positions.
* @param {string} prefix
Expand Down
13 changes: 13 additions & 0 deletions packages/marble-datatable/test/Datatable.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @jest-environment node
*/

import Component from 'metal-component';
import Datatable from '../src/Datatable';

describe('Datatable.node', () => {
it('should not fail on the server side', () => {
const datatable = Component.renderToString(Datatable);
expect(datatable).not.toBeNull();
});
});

0 comments on commit 059dc5c

Please sign in to comment.