Skip to content

Commit

Permalink
Merge branch 'master' into dependencies.io-update-build-422.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonya committed Nov 10, 2018
2 parents 2685668 + 86010d7 commit d85cd6b
Show file tree
Hide file tree
Showing 130 changed files with 214 additions and 75 deletions.
2 changes: 1 addition & 1 deletion components/icon/package.json
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@ring-ui/icon",
"version": "1.0.1",
"version": "1.0.2",
"main": "index.js",
"scripts": {
"prepublish": "node generate-exports"
Expand Down
3 changes: 1 addition & 2 deletions components/popup/popup.test.js
Expand Up @@ -67,8 +67,7 @@ describe('Popup', () => {
it('should be closed by click outside the element after show', () => {
const onCloseAttempt = sandbox.stub();
const wrapper = mountPopup({
onCloseAttempt,
...this.state
onCloseAttempt
});

wrapper.setProps({hidden: false}, () => {
Expand Down
25 changes: 19 additions & 6 deletions components/query-assist/query-assist.css
Expand Up @@ -2,6 +2,7 @@

@value unit from "../global/global.css";
@value overInputZIndex: 2;
@value inputGap: calc(unit * 3);

.light {
&.queryAssist {
Expand Down Expand Up @@ -209,11 +210,15 @@
}

&.inputGap {
border-right-width: calc(unit * 3);
border-right-width: inputGap;
}

&.inputGap2 {
border-right-width: calc(2 * inputGap);
}

&.inputLeftGap {
border-left-width: calc(unit * 3);
border-left-width: inputGap;
}

&.inputDisabled {
Expand Down Expand Up @@ -258,6 +263,13 @@
display: inline;
}

.actions {
position: absolute;
z-index: overInputZIndex;
top: 2px;
right: 1px;
}

.icon {
position: absolute;
z-index: overInputZIndex;
Expand All @@ -274,6 +286,11 @@
& svg {
vertical-align: baseline;
}

@nest .actions & {
position: relative;
top: auto;
}
}

.loaderOnTheRight {
Expand All @@ -282,10 +299,6 @@
left: auto;
}

.iconClear {
right: 1px;
}

.iconGlass {
left: 1px;
}
Expand Down
67 changes: 67 additions & 0 deletions components/query-assist/query-assist.examples.html
Expand Up @@ -285,3 +285,70 @@
);
</file>
</example>

<example name="QueryAssistWithCustomActions">
<file type="html" disable-auto-size>
<div id="example">
</div>

<div class="example-dark" id="example-dark">
</div>
</file>

<file type="js">
import React from 'react';
import {render} from 'react-dom';
import hubConfig from '@ring-ui/docs/components/hub-config';
import { PermissionIcon } from '@jetbrains/ring-ui/components/icon';

import QueryAssist from '@jetbrains/ring-ui/components/query-assist/query-assist';
import Auth from '@jetbrains/ring-ui/components/auth/auth';
import HTTP from '@jetbrains/ring-ui/components/http/http';

const log = obj => {
const div = document.createElement('div');
div.innerHTML = JSON.stringify(obj);
document.getElementById('example').appendChild(div);
};

const auth = new Auth(hubConfig);
const http = new HTTP(auth, auth.getAPIPath());

const dataSource = props => {
const params = {
query: {
...props,
fields: 'query,caret,styleRanges' + (props.omitSuggestions ? '' : ',suggestions')
}
}

return http.get('users/queryAssist', params);
}

const actions = [
<PermissionIcon
key="custom-action"
size={PermissionIcon.Size.Size16}
/>,
];
auth.init().then(() => {
render(
<QueryAssist
query="test"
placeholder="placeholder"
popupClassName="popupClassNameTest"
glass
clear
onApply={log}
focus
hint="lol"
hintOnSelection="lol selected"
popupClassName="test"
dataSource={dataSource}
actions={actions}
/>,
document.getElementById('example')
);
});
</file>
</example>
38 changes: 26 additions & 12 deletions components/query-assist/query-assist.js
Expand Up @@ -129,6 +129,7 @@ export default class QueryAssist extends Component {
query: PropTypes.string,
useCustomItemRender: PropTypes.bool,
translations: PropTypes.object,
actions: PropTypes.array,
'data-test': PropTypes.string
};

Expand Down Expand Up @@ -760,17 +761,39 @@ export default class QueryAssist extends Component {
end: noop
};

renderActions() {
const actions = [].concat(this.props.actions || []);
const renderClear = this.props.clear && !!this.state.query;

if (renderClear) {
actions.push(
<CloseIcon
key={'clearAction'}
className={classNames(styles.icon)}
title={this.props.translations.clearTitle}
iconRef={this.clearRef}
onClick={this.clearQuery}
size={CloseIcon.Size.Size16}
data-test="query-assist-clear-icon"
/>
);
}

return actions;
}

render() {
const {theme, glass, 'data-test': dataTest, useCustomItemRender} = this.props;
const renderPlaceholder = !!this.props.placeholder && this.state.placeholderEnabled;
const renderClear = this.props.clear && !!this.state.query;
const renderLoader = this.props.loader !== false && this.state.loading;
const renderGlass = glass && !renderLoader;
const renderUnderline = theme === Theme.DARK;
const actions = this.renderActions();

const inputClasses = classNames({
[`${styles.input} ring-js-shortcuts`]: true,
[styles.inputGap]: renderClear,
[styles.inputGap]: actions.length,
[styles.inputGap2]: actions.length === 2, // TODO: replace with flex-box layout
[styles.inputLeftGap]: this.isRenderingGlassOrLoader(),
[styles.inputDisabled]: this.props.disabled
});
Expand Down Expand Up @@ -846,16 +869,7 @@ export default class QueryAssist extends Component {
</span>
)}
{renderUnderline && <div className={styles.focusUnderline}/>}
{renderClear && (
<CloseIcon
className={classNames(styles.icon, styles.iconClear)}
title={this.props.translations.clearTitle}
iconRef={this.clearRef}
onClick={this.clearQuery}
size={CloseIcon.Size.Size16}
data-test="query-assist-clear-icon"
/>
)}
{actions && <div className={styles.actions}>{actions}</div>}
<PopupMenu
hidden={!this.state.showPopup}
onCloseAttempt={this.closePopup}
Expand Down
15 changes: 15 additions & 0 deletions components/query-assist/query-assist.test.js
Expand Up @@ -639,4 +639,19 @@ describe('Query Assist', () => {

});
});


describe('custom actions', () => {
it('should allow to pass custom actions', () => {
const wrapper = mountQueryAssist({
actions: [
<div id={'A'} key={'A'}/>,
<div id={'B'} key={'B'}/>
]
});

wrapper.find('#A').should.exist;
wrapper.find('#B').should.exist;
});
});
});
19 changes: 10 additions & 9 deletions components/select/select.test.js
Expand Up @@ -985,46 +985,47 @@ describe('Select', () => {

describe('Focus after close', () => {
let instance;
let targetInput;
beforeEach(() => {
this.targetInput = document.createElement('input');
document.body.appendChild(this.targetInput);
targetInput = document.createElement('input');
document.body.appendChild(targetInput);

mountSelectToContainer({
data: testData,
filter: true,
targetElement: this.targetInput
targetElement: targetInput
});
instance = mountWrapper.instance();

instance._showPopup();
});

afterEach(() => {
document.body.removeChild(this.targetInput);
this.targetInput = null;
document.body.removeChild(targetInput);
targetInput = null;
});

it('Should restore focus on provided target element after closing popup', () => {
instance._hidePopup(true);

this.targetInput.should.equal(document.activeElement);
targetInput.should.equal(document.activeElement);
});

it('Should restore focus on provided target element after closing popup with keyboard', () => {
simulateCombo('esc');
this.targetInput.should.equal(document.activeElement);
targetInput.should.equal(document.activeElement);
});

it('Should not restore focus on provided target element after closing popup with not keyboard event', () => {
Simulate.click(document.body);

this.targetInput.should.not.equal(document.activeElement);
targetInput.should.not.equal(document.activeElement);
});

it('Should not restore focus on provided target element after closing popup', () => {
instance._hidePopup();

this.targetInput.should.not.equal(document.activeElement);
targetInput.should.not.equal(document.activeElement);
});
});

Expand Down

0 comments on commit d85cd6b

Please sign in to comment.