diff --git a/docs/app/app.ts b/docs/app/app.ts index 318e4fde..fdfba6f5 100644 --- a/docs/app/app.ts +++ b/docs/app/app.ts @@ -12,7 +12,7 @@ if (macroCondition(isDevelopingApp())) { } setConfig({ - rootElement: 'body', + rootElement: config.APP['rootElement'] as string | undefined, }); export default class App extends Application { diff --git a/docs/app/components/snippets/installation-2.js.txt b/docs/app/components/snippets/installation-2.js.txt index 560a8e0b..ce8cfa2a 100644 --- a/docs/app/components/snippets/installation-2.js.txt +++ b/docs/app/components/snippets/installation-2.js.txt @@ -3,11 +3,11 @@ import { setConfig } from 'ember-basic-dropdown/config'; // Basic usage: setConfig({ - rootElement: config.APP.rootElement, // Default is 'body' (or '#ember-testing' in tests) + rootElement: config.APP.rootElement, // config.APP.rootElement is by default 'undefined' and '#ember-testing' in tests }); // Advanced: If you need to override globally the destination element ID (BasicDropdownWormhole), you can do: setConfig({ destination: 'my-custom-destination-id', - rootElement: config.APP.rootElement, // Default is 'body' (or '#ember-testing' in tests) + rootElement: config.APP.rootElement, // config.APP.rootElement is by default 'undefined' and '#ember-testing' in tests }); diff --git a/src/config.ts b/src/config.ts index 1c0d44a8..60564d18 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,31 +1,14 @@ export interface Config { destination?: string; - rootElement: string; + rootElement?: string; } -let _config: Config = { - rootElement: '', -}; - -let configSet = false; +let _config: Config = {}; export function setConfig(config: Config) { - if (!config.rootElement) { - throw new Error( - "ember-basic-dropdown: 'rootElement' is required in the config. See installation instructions for more details.", - ); - } - _config = config; - configSet = true; } export function getConfig(): Config { - if (!configSet) { - throw new Error( - 'ember-basic-dropdown: setConfig was not called before accessing config. See installation instructions for more details.', - ); - } - return _config; }