Best JavaScript code snippet using wpt
index.js
Source:index.js
1import React, { Component } from 'react'2import { connect } from 'react-redux'3import {4 Button, ButtonToolbar,5 Modal,6} from 'react-bootstrap'7import Markdown from 'react-remarkable'8import {9 mergeMapDispatchToProps,10} from 'subtender'11import { PTyp } from '../../../ptyp'12import {13 mapDispatchToProps as rootMdtp,14} from '../../../store/reducer'15import {16 mapDispatchToProps as expedConfigsMdtp,17} from '../../../store/reducer/exped-configs'18import {19 mapDispatchToProps as shipListMdtp,20} from '../../../store/reducer/ship-list'21import { translateSelector } from '../../../selectors'22const resetOptions = []23const defineReset = (id, desc) => resetOptions.push({id, desc})24defineReset('all', 'All')25defineReset('expedConfigs', 'ExpedConfigs')26defineReset('shipList', 'ShipList')27class ResetAreaImpl extends Component {28 static propTypes = {29 factoryReset: PTyp.func.isRequired,30 resetExpedConfigs: PTyp.func.isRequired,31 resetShipList: PTyp.func.isRequired,32 tr: PTyp.func.isRequired,33 }34 constructor(props) {35 super(props)36 this.state = {37 resetFocus: resetOptions[0].id,38 showModal: false,39 }40 }41 getCurrentDesc = () => {42 const {resetFocus} = this.state43 const resetDef = resetOptions.find(r => r.id === resetFocus)44 return resetDef.desc45 }46 handleChangeResetFocus = id => () => {47 const {resetFocus} = this.state48 if (resetFocus === id)49 return50 this.setState({resetFocus: id})51 }52 handleOpenResetModal = () =>53 this.setState({showModal: true})54 handleCloseResetModal = () =>55 this.setState({showModal: false})56 handleReset = () => {57 this.handleCloseResetModal()58 const {resetFocus} = this.state59 /* eslint-disable indent */60 const resetFunc =61 resetFocus === 'all' ? this.props.factoryReset :62 resetFocus === 'expedConfigs' ? this.props.resetExpedConfigs :63 resetFocus === 'shipList' ? this.props.resetShipList :64 console.error(`Unknown reset type ${resetFocus}`)65 /* eslint-enable indent */66 resetFunc()67 }68 render() {69 const {tr} = this.props70 const {resetFocus, showModal} = this.state71 return (72 <div>73 <div style={{marginBottom: '.5em'}}>74 {tr('SettingsAndTools.General.Reset.Desc')}75 </div>76 <ButtonToolbar>77 {78 resetOptions.map(({id,desc}) => {79 const isActive = id === resetFocus80 return (81 <Button82 active={isActive}83 onClick={this.handleChangeResetFocus(id)}84 bsStyle={isActive ? 'danger' : 'default'}85 key={id}>86 {tr(`SettingsAndTools.General.Reset.${desc}`)}87 </Button>88 )89 })90 }91 </ButtonToolbar>92 <div style={{display: 'flex', justifyContent: 'flex-end'}}>93 <Button94 onClick={this.handleOpenResetModal}95 >96 {tr('SettingsAndTools.General.Reset.Reset')}97 </Button>98 </div>99 <Modal100 onHide={this.handleCloseResetModal}101 show={showModal}>102 <Modal.Header closeButton>103 <Modal.Title>104 {tr('SettingsAndTools.General.Reset.ConfirmTitle')}105 </Modal.Title>106 </Modal.Header>107 <Modal.Body>108 <Markdown109 source={110 tr(111 'SettingsAndTools.General.Reset.ConfirmMsgMarkdown',112 tr(`SettingsAndTools.General.Reset.${this.getCurrentDesc()}`)113 )114 }115 />116 </Modal.Body>117 <Modal.Footer>118 <Button onClick={this.handleCloseResetModal}>119 {tr('No')}120 </Button>121 <Button122 bsStyle="danger"123 onClick={this.handleReset}124 >125 {tr('Yes')}126 </Button>127 </Modal.Footer>128 </Modal>129 </div>130 )131 }132}133const ResetArea = connect(134 translateSelector,135 mergeMapDispatchToProps(136 rootMdtp,137 expedConfigsMdtp,138 shipListMdtp139 ),140)(ResetAreaImpl)...
resetFocus.spec.js
Source:resetFocus.spec.js
...15 cleanup();16 });17 it('set focus to first element when last element is focused and event is tab', () => {18 focusOnLast();19 resetFocus({20 focusableEls: { first: first(), last: last() },21 event: fakeKeyDownEvent({ shiftKey: false }),22 });23 expect(first()).toHaveFocus();24 });25 it('set focus to last element when first element is focused and event is shift + tab', () => {26 focusOnFirst();27 resetFocus({28 focusableEls: { first: first(), last: last() },29 event: fakeKeyDownEvent({ shiftKey: true }),30 });31 expect(last()).toHaveFocus();32 });33 it(`doesn't change focus when first element is focused and event is tab`, () => {34 focusOnFirst();35 resetFocus({36 focusableEls: { first: first(), last: last() },37 event: fakeKeyDownEvent(),38 });39 expect(first()).toHaveFocus();40 });41 it(`doesn't change focus when last element is focused and event is shift+tab`, () => {42 focusOnLast();43 resetFocus({44 focusableEls: { first: first(), last: last() },45 event: fakeKeyDownEvent({ shiftKey: true }),46 });47 expect(last()).toHaveFocus();48 });49 it(`doesn't change focus when middle element is focused and event is shift+tab or tab`, () => {50 focusOnMiddle();51 resetFocus({52 focusableEls: { first: first(), last: last() },53 event: fakeKeyDownEvent({ shiftKey: true }),54 });55 expect(middle()).toHaveFocus();56 resetFocus({57 focusableEls: { first: first(), last: last() },58 event: fakeKeyDownEvent(),59 });60 expect(middle()).toHaveFocus();61 });62 it(`doesn't change focus when first is the only element provided`, () => {63 focusOnFirst();64 resetFocus({65 focusableEls: { first: first(), last: undefined },66 event: fakeKeyDownEvent({ shiftKey: true }),67 });68 expect(first()).toHaveFocus();69 });70 it(`doesn't change focus when last is the only element provided`, () => {71 focusOnLast();72 resetFocus({73 focusableEls: { first: undefined, last: last() },74 event: fakeKeyDownEvent(),75 });76 expect(last()).toHaveFocus();77 });78 const first = () => screen.getByText('first');79 const last = () => screen.getByText('last');80 const middle = () => screen.getByText('middle');81 const focusOnFirst = () => userEvent.tab();82 const focusOnLast = () => userEvent.tab({ shift: true });83 const focusOnMiddle = () => {84 userEvent.tab();85 userEvent.tab();86 };...
use-focus-pass.ts
Source:use-focus-pass.ts
...26 }27 if (!shiftKey) {28 switch (key) {29 case 'Escape': {30 return resetFocus();31 }32 case 'Enter':33 case 'ArrowRight': {34 return passFocus(1, key);35 }36 case 'ArrowLeft': {37 return passFocus(-1, key);38 }39 default: {40 // eslint-disable-next-line no-useless-return41 return;42 }43 }44 }...
Using AI Code Generation
1function resetFocus() {2 var toolbar = document.getElementById("wptoolbar");3 toolbar.resetFocus();4}5function resetFocus() {6 var toolbar = document.getElementById("wptoolbar");7 toolbar.resetFocus();8}9function resetFocus() {10 var toolbar = document.getElementById("wptoolbar");11 toolbar.resetFocus();12}13function resetFocus() {14 var toolbar = document.getElementById("wptoolbar");15 toolbar.resetFocus();16}17function resetFocus() {18 var toolbar = document.getElementById("wptoolbar");19 toolbar.resetFocus();20}21function resetFocus() {22 var toolbar = document.getElementById("wptoolbar");23 toolbar.resetFocus();24}25function resetFocus() {26 var toolbar = document.getElementById("wptoolbar");27 toolbar.resetFocus();28}29function resetFocus() {30 var toolbar = document.getElementById("wptoolbar");31 toolbar.resetFocus();32}33function resetFocus() {34 var toolbar = document.getElementById("wptoolbar");35 toolbar.resetFocus();36}37function resetFocus() {38 var toolbar = document.getElementById("wptoolbar");39 toolbar.resetFocus();40}
Using AI Code Generation
1function testResetFocus()2{3 var toolbar = document.getElementById("wptoolbar");4 toolbar.resetFocus();5}6function testSetFocus()7{8 var toolbar = document.getElementById("wptoolbar");9 toolbar.setFocus();10}11function testSetFocusOnFirst()12{13 var toolbar = document.getElementById("wptoolbar");14 toolbar.setFocusOnFirst();15}16function testSetFocusOnLast()17{18 var toolbar = document.getElementById("wptoolbar");19 toolbar.setFocusOnLast();20}21function testSetFocusOnNext()22{23 var toolbar = document.getElementById("wptoolbar");24 toolbar.setFocusOnNext();25}26function testSetFocusOnPrevious()27{28 var toolbar = document.getElementById("wptoolbar");29 toolbar.setFocusOnPrevious();30}31function testSetFocusToButton()32{33 var toolbar = document.getElementById("wptoolbar");34 var button = document.getElementById("button1");35 toolbar.setFocusToButton(button);36}37function testSetFocusToItem()38{39 var toolbar = document.getElementById("wptoolbar");40 var button = document.getElementById("button1");41 toolbar.setFocusToItem(button);42}43function testSetFocusToNextItem()44{45 var toolbar = document.getElementById("wptoolbar");46 toolbar.setFocusToNextItem();47}48function testSetFocusToPreviousItem()49{50 var toolbar = document.getElementById("wptoolbar");51 toolbar.setFocusToPreviousItem();52}
Using AI Code Generation
1function resetFocus() {2 const table = document.querySelector('.wptb-preview-table');3 const tableState = new wptbTableState(table);4 tableState.resetFocus();5}6#### `wptbTableState.setCellFocus()`7function setCellFocus() {8 const table = document.querySelector('.wptb-preview-table');9 const tableState = new wptbTableState(table);10 tableState.setCellFocus();11}12#### `wptbTableState.setCellFocusToCell()`13function setCellFocusToCell() {14 const table = document.querySelector('.wptb-preview-table');15 const tableState = new wptbTableState(table);16 const cell = table.querySelector('.wptb-cell');17 tableState.setCellFocusToCell(cell);18}19#### `wptbTableState.setCellFocusToNext()`20function setCellFocusToNext() {21 const table = document.querySelector('.wptb-preview-table');22 const tableState = new wptbTableState(table);23 tableState.setCellFocusToNext();24}25#### `wptbTableState.setCellFocusToPrevious()`26function setCellFocusToPrevious() {27 const table = document.querySelector('.wptb-preview-table');28 const tableState = new wptbTableState(table);29 tableState.setCellFocusToPrevious();30}31#### `wptbTableState.setCellFocusToTop()`
Using AI Code Generation
1var toolbar = document.getElementById("wptoolbar");2var toolbarItems = toolbar.getElementsByTagName("toolbaritem");3var toolbarItem = toolbarItems[0];4toolbarItem.focus();5toolbarItem = toolbarItems[1];6toolbarItem.focus();7toolbarItem = toolbarItems[2];8toolbarItem.focus();9toolbarItem = toolbarItems[3];10toolbarItem.focus();11toolbarItem = toolbarItems[4];12toolbarItem.focus();13toolbarItem = toolbarItems[5];14toolbarItem.focus();15toolbarItem = toolbarItems[6];16toolbarItem.focus();17toolbarItem = toolbarItems[7];18toolbarItem.focus();19toolbarItem = toolbarItems[8];20toolbarItem.focus();21toolbarItem = toolbarItems[9];22toolbarItem.focus();23toolbarItem = toolbarItems[10];24toolbarItem.focus();25toolbarItem = toolbarItems[11];26toolbarItem.focus();27toolbarItem = toolbarItems[12];28toolbarItem.focus();29toolbarItem = toolbarItems[13];30toolbarItem.focus();31toolbarItem = toolbarItems[14];32toolbarItem.focus();33toolbarItem = toolbarItems[15];34toolbarItem.focus();35toolbarItem = toolbarItems[16];36toolbarItem.focus();37toolbarItem = toolbarItems[17];38toolbarItem.focus();39toolbarItem = toolbarItems[18];40toolbarItem.focus();41toolbarItem = toolbarItems[19];42toolbarItem.focus();43toolbarItem = toolbarItems[20];44toolbarItem.focus();45toolbarItem = toolbarItems[21];46toolbarItem.focus();47toolbarItem = toolbarItems[22];48toolbarItem.focus();49toolbarItem = toolbarItems[23];50toolbarItem.focus();51toolbarItem = toolbarItems[24];52toolbarItem.focus();53toolbarItem = toolbarItems[25];54toolbarItem.focus();55toolbarItem = toolbarItems[26];56toolbarItem.focus();57toolbarItem = toolbarItems[27];58toolbarItem.focus();59toolbarItem = toolbarItems[28];60toolbarItem.focus();61toolbarItem = toolbarItems[29];62toolbarItem.focus();63toolbarItem = toolbarItems[30];64toolbarItem.focus();65toolbarItem = toolbarItems[31];66toolbarItem.focus();67toolbarItem = toolbarItems[32];68toolbarItem.focus();69toolbarItem = toolbarItems[33];70toolbarItem.focus();71toolbarItem = toolbarItems[34];72toolbarItem.focus();73toolbarItem = toolbarItems[35];74toolbarItem.focus();75toolbarItem = toolbarItems[36];76toolbarItem.focus();77toolbarItem = toolbarItems[37];78toolbarItem.focus();
Using AI Code Generation
1let table = document.querySelector('.wptb-preview-table');2let tableSettings = new wptbTableSettigs(table);3tableSettings.resetFocus();4let table = document.querySelector('.wptb-preview-table');5let tableSettings = new wptbTableSettigs(table);6tableSettings.addFocus();7let table = document.querySelector('.wptb-preview-table');8let tableSettings = new wptbTableSettigs(table);9tableSettings.removeFocus();10let table = document.querySelector('.wptb-preview-table');11let tableSettings = new wptbTableSettigs(table);12let focus = tableSettings.getFocus();13console.log(focus);14let table = document.querySelector('.wptb-preview-table');15let tableSettings = new wptbTableSettigs(table);16tableSettings.setFocus([1,1]);17let table = document.querySelector('.wptb-preview-table');18let tableSettings = new wptbTableSettigs(table);19let selection = tableSettings.getSelection();20console.log(selection);21let table = document.querySelector('.wptb-preview-table');22let tableSettings = new wptbTableSettigs(table);23tableSettings.setSelection([1,1], [2,2]);
Using AI Code Generation
1var tabs = new WPTabs(document.getElementById('tabs'), {2});3tabs.resetFocus();4var tabs = new WPTabs(document.getElementById('tabs'), {5});6tabs.resetFocus();7var tabs = new WPTabs(document.getElementById('tabs'), {8});9tabs.setFocus(1);10var tabs = new WPTabs(document.getElementById('tabs'), {11});12tabs.setFocusByHash('tab-2');13var tabs = new WPTabs(document.getElementById('tabs'), {14});15tabs.setFocusByLabel('Tab 2');16var tabs = new WPTabs(document.getElementById('tabs'), {17});18tabs.setFocusByTitle('Tab 2');19var tabs = new WPTabs(document.getElementById('tabs'), {20});21tabs.setFocusByValue('tab-2');22var tabs = new WPTabs(document.getElementById('tabs'), {23});24tabs.setFocusByIndex(1);
Using AI Code Generation
1function resetFocus() {2 wptbTableSetup.resetFocus();3}4function setDraggable() {5 wptbTableSetup.setDraggable(true);6}7function setResizable() {8 wptbTableSetup.setResizable(true);9}10function setCellEditable() {11 wptbTableSetup.setCellEditable(true);12}13function setCellSelectable() {14 wptbTableSetup.setCellSelectable(true);15}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!